emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 3000edc6179: Use the nthcdr byte-op for drop, and raise open-code


From: Mattias Engdegård
Subject: master 3000edc6179: Use the nthcdr byte-op for drop, and raise open-code limit
Date: Mon, 29 Apr 2024 16:17:12 -0400 (EDT)

branch: master
commit 3000edc6179dfe0b5f24ae2e472826530809dfd1
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Use the nthcdr byte-op for drop, and raise open-code limit
    
    * lisp/emacs-lisp/byte-opt.el (byte-optimize-nthcdr):
    Open-code for any integral N<5.  Always use the byte-op otherwise.
---
 lisp/emacs-lisp/byte-opt.el | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 3d6b35422b8..4095726d276 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]