aboutsummaryrefslogtreecommitdiff
path: root/compat-29.el
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2024-01-13 23:53:42 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2024-01-13 23:57:10 +0100
commit1bf572df407f3e40fa062810ac2e7342b4eca140 (patch)
tree53589dd841533c733de0f09dff3080454b3cb415 /compat-29.el
parentf94ddcc1680089121e6476ae55a506a72b18a68c (diff)
compat-29: Use lax-plist-get and lax-plist-put as optimization
Diffstat (limited to 'compat-29.el')
-rw-r--r--compat-29.el50
1 files changed, 26 insertions, 24 deletions
diff --git a/compat-29.el b/compat-29.el
index cd01210..5b0a4df 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -102,38 +102,40 @@ Unibyte strings are converted to multibyte for comparison."
(compat-defun plist-get (plist prop &optional predicate) ;; <compat-tests:plist-get>
"Handle optional argument PREDICATE."
:extended t
- (if (or (null predicate) (eq predicate 'eq))
- (plist-get plist prop)
- (catch 'found
- (while (consp plist)
- (when (funcall predicate prop (car plist))
- (throw 'found (cadr plist)))
- (setq plist (cddr plist))))))
+ (pcase predicate
+ ((or `nil `eq) (plist-get plist prop))
+ (`equal (lax-plist-get plist prop))
+ (_ (catch 'found
+ (while (consp plist)
+ (when (funcall predicate prop (car plist))
+ (throw 'found (cadr plist)))
+ (setq plist (cddr plist)))))))
(compat-defun plist-put (plist prop val &optional predicate) ;; <compat-tests:plist-get>
"Handle optional argument PREDICATE."
:extended t
- (if (or (null predicate) (eq predicate 'eq))
- (plist-put plist prop val)
- (catch 'found
- (let ((tail plist))
- (while (consp tail)
- (when (funcall predicate prop (car tail))
- (setcar (cdr tail) val)
- (throw 'found plist))
- (setq tail (cddr tail))))
- (nconc plist (list prop val)))))
+ (pcase predicate
+ ((or `nil `eq) (plist-put plist prop val))
+ (`equal (lax-plist-put plist prop val))
+ (_ (catch 'found
+ (let ((tail plist))
+ (while (consp tail)
+ (when (funcall predicate prop (car tail))
+ (setcar (cdr tail) val)
+ (throw 'found plist))
+ (setq tail (cddr tail))))
+ (nconc plist (list prop val))))))
(compat-defun plist-member (plist prop &optional predicate) ;; <compat-tests:plist-get>
"Handle optional argument PREDICATE."
:extended t
- (if (or (null predicate) (eq predicate 'eq))
- (plist-member plist prop)
- (catch 'found
- (while (consp plist)
- (when (funcall predicate prop (car plist))
- (throw 'found plist))
- (setq plist (cddr plist))))))
+ (pcase predicate
+ ((or `nil `eq) (plist-member plist prop))
+ (_ (catch 'found
+ (while (consp plist)
+ (when (funcall predicate prop (car plist))
+ (throw 'found plist))
+ (setq plist (cddr plist)))))))
;;;; Defined in gv.el