diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2023-02-15 12:01:25 +0100 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2023-02-15 12:04:13 +0100 |
commit | 16ba96ad3ddbd5607a2e40ffe5abfe53c3e6a1c5 (patch) | |
tree | 7b40855dacc0bdf813e93b0f8fe236e30478861a /lisp/subr.el | |
parent | 51e3f91f50da43f18706410bf6cd096684379daa (diff) | |
download | emacs-16ba96ad3ddbd5607a2e40ffe5abfe53c3e6a1c5.tar.gz |
Add some `pure` and `side-effect-free` declarations
* lisp/subr.el (string-to-list, string-to-vector, string-or-null-p)
(booleanp, special-form-p, plistp, macrop, compiled-function-p)
(flatten-tree):
* lisp/emacs-lisp/subr-x.el (string-join, string-truncate-left)
(string-blank-p, string-remove-prefix, string-remove-suffix)
(string-pad, string-chop-newline):
Declare functions pure, side-effect-free, and/or error-free.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 898ecb6e358..a5fc566cc74 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4124,15 +4124,18 @@ system's shell." (defsubst string-to-list (string) "Return a list of characters in STRING." + (declare (side-effect-free t)) (append string nil)) (defsubst string-to-vector (string) "Return a vector of characters in STRING." + (declare (side-effect-free t)) (vconcat string)) (defun string-or-null-p (object) "Return t if OBJECT is a string or nil. Otherwise, return nil." + (declare (pure t) (side-effect-free error-free)) (or (stringp object) (null object))) (defun list-of-strings-p (object) @@ -4145,21 +4148,25 @@ Otherwise, return nil." (defun booleanp (object) "Return t if OBJECT is one of the two canonical boolean values: t or nil. Otherwise, return nil." + (declare (pure t) (side-effect-free error-free)) (and (memq object '(nil t)) t)) (defun special-form-p (object) "Non-nil if and only if OBJECT is a special form." + (declare (side-effect-free error-free)) (if (and (symbolp object) (fboundp object)) (setq object (indirect-function object))) (and (subrp object) (eq (cdr (subr-arity object)) 'unevalled))) (defun plistp (object) "Non-nil if and only if OBJECT is a valid plist." + (declare (pure t) (side-effect-free error-free)) (let ((len (proper-list-p object))) (and len (zerop (% len 2))))) (defun macrop (object) "Non-nil if and only if OBJECT is a macro." + (declare (side-effect-free t)) (let ((def (indirect-function object))) (when (consp def) (or (eq 'macro (car def)) @@ -4169,6 +4176,7 @@ Otherwise, return nil." "Return non-nil if OBJECT is a function that has been compiled. Does not distinguish between functions implemented in machine code or byte-code." + (declare (side-effect-free error-free)) (or (subrp object) (byte-code-function-p object))) (defun field-at-pos (pos) @@ -6843,6 +6851,7 @@ returned list are in the same order as in TREE. \(flatten-tree \\='(1 (2 . 3) nil (4 5 (6)) 7)) => (1 2 3 4 5 6 7)" + (declare (side-effect-free error-free)) (let (elems) (while (consp tree) (let ((elem (pop tree))) |