Skip to content

Commit 5464139

Browse files
yuhan0bbatsov
authored andcommitted
Improve performance of nrepl-dict-get
Avoid full traversal of dict in 2-argument call
1 parent 451f72e commit 5464139

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

nrepl-dict.el

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ If dict is nil, return nil. If DEFAULT not provided, and KEY not in DICT,
6666
return nil. If DICT is not an nREPL dict object, an error is thrown."
6767
(when dict
6868
(if (nrepl-dict-p dict)
69-
(if (nrepl-dict-contains dict key)
70-
(lax-plist-get (cdr dict) key)
71-
default)
69+
;; Note: The structure of the following expression avoids the
70+
;; expensive containment check in nearly all cases, see #3717
71+
(or (lax-plist-get (cdr dict) key)
72+
(when default
73+
(and (not (nrepl-dict-contains dict key))
74+
default)))
7275
(error "Not an nREPL dict object: %s" dict))))
7376

7477
(defun nrepl-dict-put (dict key value)

0 commit comments

Comments
 (0)