emacs-diffs
[Top][All Lists]
Advanced

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

master 4da0fbdc82: Faster and more robust list-of-strings-p


From: Mattias Engdegård
Subject: master 4da0fbdc82: Faster and more robust list-of-strings-p
Date: Fri, 16 Sep 2022 09:34:21 -0400 (EDT)

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

    Faster and more robust list-of-strings-p
    
    * lisp/subr.el (list-of-strings-p): Speed up by a factor 4 (approx.)
    and don't crash on dotted lists.
    * test/lisp/subr-tests.el (test-list-of-strings-p): Extend test.
---
 lisp/subr.el            | 5 +++--
 test/lisp/subr-tests.el | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index e8e8f1584b..caea2b9f93 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4028,8 +4028,9 @@ Otherwise, return nil."
 
 (defun list-of-strings-p (object)
   "Return t if OBJECT is nil or a list of strings."
-  (and (listp object)
-       (seq-every-p #'stringp object)))
+  (while (and (consp object) (stringp (car object)))
+    (setq object (cdr object)))
+  (null object))
 
 (defun booleanp (object)
   "Return t if OBJECT is one of the two canonical boolean values: t or nil.
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 38966cea58..347981e818 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -1163,7 +1163,8 @@ final or penultimate step during initialization."))
   (should (list-of-strings-p nil))
   (should (list-of-strings-p '("a" "b")))
   (should-not (list-of-strings-p ["a" "b"]))
-  (should-not (list-of-strings-p '("a" nil "b"))))
+  (should-not (list-of-strings-p '("a" nil "b")))
+  (should-not (list-of-strings-p '("a" "b" . "c"))))
 
 (provide 'subr-tests)
 ;;; subr-tests.el ends here



reply via email to

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