]> git.eshelyaron.com Git - emacs.git/commitdiff
Use the nthcdr byte-op for drop, and raise open-code limit
authorMattias EngdegÄrd <mattiase@acm.org>
Mon, 29 Apr 2024 18:24:07 +0000 (20:24 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 30 Apr 2024 07:40:43 +0000 (09:40 +0200)
* lisp/emacs-lisp/byte-opt.el (byte-optimize-nthcdr):
Open-code for any integral N<5.  Always use the byte-op otherwise.

(cherry picked from commit 3000edc6179dfe0b5f24ae2e472826530809dfd1)

lisp/emacs-lisp/byte-opt.el

index 3d6b35422b8fe2f9abe6269650b206ce1d5365d7..4095726d27681e9e3f202b122a59fe7939a94ec4 100644 (file)
@@ -1512,13 +1512,15 @@ See Info node `(elisp) Integer Basics'."
 (put 'nthcdr 'byte-optimizer #'byte-optimize-nthcdr)
 (defun byte-optimize-nthcdr (form)
   (if (= (safe-length form) 3)
-      (if (memq (nth 1 form) '(0 1 2))
-         (let ((count (nth 1 form)))
-           (setq form (nth 2 form))
-           (while (>= (setq count (1- count)) 0)
-             (setq form (list 'cdr form)))
-           form)
-       form)
+      (let ((count (nth 1 form)))
+        (cond ((and (integerp count) (<= count 3))
+              (setq form (nth 2 form))
+              (while (>= (setq count (1- count)) 0)
+                (setq form (list 'cdr form)))
+              form)
+              ((not (eq (car form) 'nthcdr))
+               (cons 'nthcdr (cdr form)))  ; use the nthcdr byte-op
+              (t form)))
     form))
 
 (put 'cons 'byte-optimizer #'byte-optimize-cons)