destructuring lambda lists inefficiently traverse the list of supplied keyword arguments twice, once to check if the keyword was supplied and a second time to return the value
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Wishlist
|
Douglas Katzman |
Bug Description
What I do:
(destructuring-bind (&key a b c d e f g h i) '(:c c :f f :h h)
(values a b c d e f g h i))
What happens:
Here's the expansion:
(LET ((#:WHOLE1147 '(:C C :F F :H H)))
(DECLARE (TYPE LIST #:WHOLE1147))
(LET* ((#:KEYWORDS-1149 #:WHOLE1147))
(DECLARE (SB-EXT:
(DECLARE (IGNORABLE #:KEYWORDS-1149))
(MULTIPLE-
(WHEN #:PROBLEM1150
(ERROR 'SB-KERNEL:
(LET* ((A
(IF (SB-KERNEL:
(B
(IF (SB-KERNEL:
(C
(IF (SB-KERNEL:
(D
(IF (SB-KERNEL:
(E
(IF (SB-KERNEL:
(F
(IF (SB-KERNEL:
(G
(IF (SB-KERNEL:
(H
(IF (SB-KERNEL:
(I
(IF (SB-KERNEL:
(VALUES A B C D E F G H I))))
Here's the implementation of SB-KERNEL:
(defun keyword-supplied-p (keyword key-list)
(do ((remaining key-list (cddr remaining)))
((endp remaining))
(when (eq keyword (car remaining))
(return t))))
Here's the implementation of SB-KERNEL:
(defun lookup-keyword (keyword key-list)
(do ((remaining key-list (cddr remaining)))
((endp remaining))
(when (eq keyword (car remaining))
(return (cadr remaining)))))
The wastage is manifest.
What I expected to happen:
SBCL should check to see if the keyword is supplied and fetch the value in one step.
SBCL version: 1.0.42
uname -a: Linux dynamorph 2.6.32-27-generic #49-Ubuntu SMP Wed Dec 1 23:52:12 UTC 2010 i686 GNU/Linux
*features*:
(:SWANK :QUICKLISP :SB-BSD-
:SBCL :SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS :SB-UNICODE :SB-EVAL
:SB-SOURCE-
:LARGEFILE :GENCGC :STACK-
:COMPARE-
:STACK-
:STACK-
:CYCLE-COUNTER :INLINE-CONSTANTS :MEMORY-
:OS-PROVIDES-
Changed in sbcl: | |
assignee: | nobody → Douglas Katzman (dougk) |
Changed in sbcl: | |
status: | Triaged → Fix Committed |
Changed in sbcl: | |
status: | Fix Committed → Fix Released |
I would be happy to merge a patch that does this, as long as it doesn't complicate the code.
I am, however, not likely to ever work on this myself absent a test-case where this actually shows up as a performance issue. :)