diff options
author | Stefan Kangas <stefankangas@gmail.com> | 2025-02-13 04:24:05 +0100 |
---|---|---|
committer | Stefan Kangas <stefankangas@gmail.com> | 2025-02-13 17:50:40 +0100 |
commit | 7d9e67be13f72b7c7c8815f651c8fa5f74a79c54 (patch) | |
tree | 30e6f718c85fda0f8e82e1659af899b2c6cd5471 /lisp/emacs-lisp/cl-lib.el | |
parent | 745847ba8eca27e981a50ad91b628bbce35bb0f3 (diff) | |
download | emacs-7d9e67be13f72b7c7c8815f651c8fa5f74a79c54.tar.gz emacs-7d9e67be13f72b7c7c8815f651c8fa5f74a79c54.tar.bz2 emacs-7d9e67be13f72b7c7c8815f651c8fa5f74a79c54.zip |
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
Diffstat (limited to 'lisp/emacs-lisp/cl-lib.el')
-rw-r--r-- | lisp/emacs-lisp/cl-lib.el | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el index 20d2c8d6a68..1ec850cf0e8 100644 --- a/lisp/emacs-lisp/cl-lib.el +++ b/lisp/emacs-lisp/cl-lib.el @@ -272,20 +272,24 @@ so that they are registered at compile-time as well as run-time." (defsubst cl-plusp (number) "Return t if NUMBER is positive." + (declare (side-effect-free t)) (> number 0)) (defsubst cl-minusp (number) "Return t if NUMBER is negative." + (declare (side-effect-free t)) (< number 0)) (defun cl-oddp (integer) "Return t if INTEGER is odd." - (declare (compiler-macro (lambda (_) `(eq (logand ,integer 1) 1)))) + (declare (side-effect-free t) + (compiler-macro (lambda (_) `(eq (logand ,integer 1) 1)))) (eq (logand integer 1) 1)) (defun cl-evenp (integer) "Return t if INTEGER is even." - (declare (compiler-macro (lambda (_) `(eq (logand ,integer 1) 0)))) + (declare (side-effect-free t) + (compiler-macro (lambda (_) `(eq (logand ,integer 1) 0)))) (eq (logand integer 1) 0)) (defconst cl-digit-char-table @@ -387,32 +391,38 @@ SEQ, this is like `mapcar'. With several, it is like the Common Lisp (defsubst cl-fifth (x) "Return the fifth element of the list X." - (declare (gv-setter (lambda (store) `(setcar (nthcdr 4 ,x) ,store)))) + (declare (side-effect-free t) + (gv-setter (lambda (store) `(setcar (nthcdr 4 ,x) ,store)))) (nth 4 x)) (defsubst cl-sixth (x) "Return the sixth element of the list X." - (declare (gv-setter (lambda (store) `(setcar (nthcdr 5 ,x) ,store)))) + (declare (side-effect-free t) + (gv-setter (lambda (store) `(setcar (nthcdr 5 ,x) ,store)))) (nth 5 x)) (defsubst cl-seventh (x) "Return the seventh element of the list X." - (declare (gv-setter (lambda (store) `(setcar (nthcdr 6 ,x) ,store)))) + (declare (side-effect-free t) + (gv-setter (lambda (store) `(setcar (nthcdr 6 ,x) ,store)))) (nth 6 x)) (defsubst cl-eighth (x) "Return the eighth element of the list X." - (declare (gv-setter (lambda (store) `(setcar (nthcdr 7 ,x) ,store)))) + (declare (side-effect-free t) + (gv-setter (lambda (store) `(setcar (nthcdr 7 ,x) ,store)))) (nth 7 x)) (defsubst cl-ninth (x) "Return the ninth element of the list X." - (declare (gv-setter (lambda (store) `(setcar (nthcdr 8 ,x) ,store)))) + (declare (side-effect-free t) + (gv-setter (lambda (store) `(setcar (nthcdr 8 ,x) ,store)))) (nth 8 x)) (defsubst cl-tenth (x) "Return the tenth element of the list X." - (declare (gv-setter (lambda (store) `(setcar (nthcdr 9 ,x) ,store)))) + (declare (side-effect-free t) + (gv-setter (lambda (store) `(setcar (nthcdr 9 ,x) ,store)))) (nth 9 x)) (defalias 'cl-caaar #'caaar) @@ -456,7 +466,8 @@ SEQ, this is like `mapcar'. With several, it is like the Common Lisp Thus, `(cl-list* A B C D)' is equivalent to `(nconc (list A B C) D)', or to `(cons A (cons B (cons C D)))'. \n(fn ARG...)" - (declare (compiler-macro cl--compiler-macro-list*)) + (declare (side-effect-free error-free) + (compiler-macro cl--compiler-macro-list*)) (cond ((not rest) arg) ((not (cdr rest)) (cons arg (car rest))) (t (let* ((n (length rest)) @@ -467,6 +478,7 @@ Thus, `(cl-list* A B C D)' is equivalent to `(nconc (list A B C) D)', or to (defun cl-ldiff (list sublist) "Return a copy of LIST with the tail SUBLIST removed." + (declare (side-effect-free t)) (let ((res nil)) (while (and (consp list) (not (eq list sublist))) (push (pop list) res)) @@ -523,6 +535,7 @@ Return a copy of TREE with all elements `eql' to OLD replaced by NEW. (defun cl-acons (key value alist) "Add KEY and VALUE to ALIST. Return a new list with (cons KEY VALUE) as car and ALIST as cdr." + (declare (side-effect-free error-free)) (cons (cons key value) alist)) (defun cl-pairlis (keys values &optional alist) @@ -530,6 +543,7 @@ Return a new list with (cons KEY VALUE) as car and ALIST as cdr." Return a new alist composed by associating KEYS to corresponding VALUES; the process stops as soon as KEYS or VALUES run out. If ALIST is non-nil, the new pairs are prepended to it." + (declare (side-effect-free t)) (nconc (cl-mapcar 'cons keys values) alist)) ;;; Miscellaneous. |