Add more function declarations

* lisp/subr.el (buffer-narrowed-p, sha1, match-substitute-replacement)
(version-to-list, version<, version<=, version=)
(function-get, subregexp-context-p, split-string)
(combine-and-quote-strings, split-string-and-unquote)
(replace-regexp-in-string, syntax-after)
(string-trim-left, string-trim):
* lisp/emacs-lisp/subr-x.el (hash-table-empty-p, hash-table-keys)
(hash-table-values, string-glyph-split)
(string-clean-whitespace, string-fill, string-limit)
(string-pixel-width):
* lisp/env.el (substitute-env-vars, substitute-env-in-file-name)
(setenv-internal):
* lisp/emacs-lisp/rx.el (rx-to-string):
* lisp/emacs-lisp/regexp-opt.el (regexp-opt-depth)
(regexp-opt-charset):
Add appropriate declarations: pure, side-effect-free, and/or
important-return-value.
This commit is contained in:
Mattias Engdegård 2023-05-26 12:28:15 +02:00
parent 54ac1165bc
commit ef778f5143
5 changed files with 32 additions and 1 deletions

View file

@ -154,6 +154,7 @@ usually more efficient than that of a simplified version:
"Return the depth of REGEXP.
This means the number of non-shy regexp grouping constructs
\(parenthesized expressions) in REGEXP."
(declare (pure t) (side-effect-free t))
(save-match-data
;; Hack to signal an error if REGEXP does not have balanced parentheses.
(string-match regexp "")
@ -270,6 +271,7 @@ Merges keywords to avoid backtracking in Emacs's regexp matcher."
CHARS should be a list of characters.
If CHARS is the empty list, the return value is a regexp that
never matches anything."
(declare (pure t) (side-effect-free t))
;; The basic idea is to find character ranges. Also we take care in the
;; position of character set meta characters in the character set regexp.
;;

View file

@ -1144,6 +1144,7 @@ If NO-GROUP is non-nil, don't bracket the result in a non-capturing
group.
For extending the `rx' notation in FORM, use `rx-define' or `rx-let-eval'."
(declare (important-return-value t))
(let* ((item (rx--translate form))
(exprs (if no-group
(car item)

View file

@ -81,18 +81,22 @@ Note how the single `-' got converted into a list before
threading."
(declare (indent 0) (debug thread-first))
`(internal--thread-argument nil ,@forms))
(defsubst hash-table-empty-p (hash-table)
"Check whether HASH-TABLE is empty (has 0 elements)."
(declare (side-effect-free t))
(zerop (hash-table-count hash-table)))
(defsubst hash-table-keys (hash-table)
"Return a list of keys in HASH-TABLE."
(declare (side-effect-free t))
(let ((keys nil))
(maphash (lambda (k _) (push k keys)) hash-table)
keys))
(defsubst hash-table-values (hash-table)
"Return a list of values in HASH-TABLE."
(declare (side-effect-free t))
(let ((values nil))
(maphash (lambda (_ v) (push v values)) hash-table)
values))
@ -149,6 +153,7 @@ carriage return."
All sequences of whitespaces in STRING are collapsed into a
single space character, and leading/trailing whitespace is
removed."
(declare (important-return-value t))
(let ((blank "[[:blank:]\r\n]+"))
(string-trim (replace-regexp-in-string blank " " string t t)
blank blank)))
@ -158,6 +163,7 @@ removed."
Wrapping is done where there is whitespace. If there are
individual words in STRING that are longer than LENGTH, the
result will have lines that are longer than LENGTH."
(declare (important-return-value t))
(with-temp-buffer
(insert string)
(goto-char (point-min))
@ -189,6 +195,7 @@ coding system that doesn't specify a BOM, like `utf-16le' or `utf-16be'.
When shortening strings for display purposes,
`truncate-string-to-width' is almost always a better alternative
than this function."
(declare (important-return-value t))
(unless (natnump length)
(signal 'wrong-type-argument (list 'natnump length)))
(if coding-system
@ -324,6 +331,7 @@ as the new values of the bound variables in the recursive invocation."
;;;###autoload
(defun string-pixel-width (string)
"Return the width of STRING in pixels."
(declare (important-return-value t))
(if (zerop (length string))
0
;; Keeping a work buffer around is more efficient than creating a
@ -344,6 +352,7 @@ This takes into account combining characters and grapheme clusters:
if compositions are enabled, each sequence of characters composed
on display into a single grapheme cluster is treated as a single
indivisible unit."
(declare (side-effect-free t))
(let ((result nil)
(start 0)
comp)