diff options
| author | Dmitry Gutov | 2023-11-21 03:18:45 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2023-11-21 03:18:45 +0200 |
| commit | 1f6fdf123bf393ea36ace9dfe1bd97a894996ed7 (patch) | |
| tree | 2f48df3e37c33e5587808fa09123f304e599eb12 | |
| parent | 94849ba35f40393362050b5937578dcf3076b4bf (diff) | |
| download | emacs-feature/cl-lib-improvements.tar.gz emacs-feature/cl-lib-improvements.zip | |
(seq-contains-pred): Split off list-specialized impl into separate methodfeature/cl-lib-improvements
* lisp/emacs-lisp/seq.el (seq-contains-pred): Split off
list-specialized impl into separate method. The result is a bit
slower (about 10%?), but better structured.
| -rw-r--r-- | lisp/emacs-lisp/seq.el | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 832a49d7845..d85c7297ee0 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el | |||
| @@ -463,22 +463,25 @@ whether an element was found or not." | |||
| 463 | ;; (t | 463 | ;; (t |
| 464 | ;; (cl-call-next-method)))) | 464 | ;; (cl-call-next-method)))) |
| 465 | 465 | ||
| 466 | (cl-defgeneric seq-contains-pred (sequence &optional testfn) | 466 | (cl-defgeneric seq-contains-pred (_sequence &optional testfn) |
| 467 | (lambda (elt sequence) | ||
| 468 | (catch 'seq--break | ||
| 469 | (seq-doseq (e sequence) | ||
| 470 | (let ((r (funcall testfn e elt))) | ||
| 471 | (when r | ||
| 472 | (throw 'seq--break r)))) | ||
| 473 | nil))) | ||
| 474 | |||
| 475 | (cl-defmethod seq-contains-pred ((_sequence list) &optional testfn) | ||
| 467 | (cond | 476 | (cond |
| 468 | ((and (listp sequence) (or (null testfn) (eq testfn 'equal))) | 477 | ((or (null testfn) (eq testfn 'equal)) |
| 469 | #'member) | 478 | #'member) |
| 470 | ((and (listp sequence) (eq testfn 'eql)) | 479 | ((eq testfn 'eql) |
| 471 | #'memql) | 480 | #'memql) |
| 472 | ((and (listp sequence) (eq testfn 'eq)) | 481 | ((eq testfn 'eq) |
| 473 | #'memq) | 482 | #'memq) |
| 474 | (t | 483 | (t |
| 475 | (lambda (elt sequence) | 484 | (cl-call-next-method)))) |
| 476 | (catch 'seq--break | ||
| 477 | (seq-doseq (e sequence) | ||
| 478 | (let ((r (funcall testfn e elt))) | ||
| 479 | (when r | ||
| 480 | (throw 'seq--break r)))) | ||
| 481 | nil))))) | ||
| 482 | 485 | ||
| 483 | (cl-defgeneric seq-set-equal-p (sequence1 sequence2 &optional testfn) | 486 | (cl-defgeneric seq-set-equal-p (sequence1 sequence2 &optional testfn) |
| 484 | "Return non-nil if SEQUENCE1 and SEQUENCE2 contain the same elements. | 487 | "Return non-nil if SEQUENCE1 and SEQUENCE2 contain the same elements. |