;;;; -- WHN 20000127
(declaim (maybe-inline
- adjoin tree-equal nth %setnth nthcdr make-list
+ tree-equal nth %setnth nthcdr make-list
member-if member-if-not tailp union
nunion intersection nintersection set-difference nset-difference
set-exclusive-or nset-exclusive-or subsetp acons
;;;; Specialized versions
-;;; %MEMBER-* and %ASSOC-* functions. The transforms for MEMBER and
-;;; ASSOC pick the appropriate version. These win because they have
-;;; only positional arguments, the TEST, TEST-NOT & KEY functions are
-;;; known to exist (or not), and are known to be functions instead of
-;;; function designators. We are also able to transform many common
-;;; cases to -EQ versions, which are substantially faster then EQL
-;;; using ones.
+;;; %ADJOIN-*, %ASSOC-*, and %MEMBER-* functions. Deftransforms
+;;; delegate to TRANSFORM-LIST-ITEM-SEEK which picks the appropriate
+;;; version. These win because they have only positional arguments,
+;;; the TEST, TEST-NOT & KEY functions are known to exist (or not),
+;;; and are known to be functions instead of function designators. We
+;;; are also able to transform many common cases to -EQ versions,
+;;; which are substantially faster then EQL using ones.
(macrolet
((def (funs form &optional variant)
(flet ((%def (name)
- `(defun ,(intern (format nil "%~A~{-~A~}~@[-~A~]" name funs variant))
- (item list ,@funs)
- (declare (optimize speed))
- ,@(when funs `((declare (function ,@funs))))
- (do ((list list (cdr list)))
- ((null list) nil)
- (declare (list list))
- (let ((this (car list)))
- ,(ecase name
- (assoc
- (if funs
- `(when this
- (let ((target (car this)))
+ (let* ((body-loop
+ `(do ((list list (cdr list)))
+ ((null list) nil)
+ (declare (list list))
+ (let ((this (car list)))
+ ,(ecase name
+ (assoc
+ (if funs
+ `(when this
+ (let ((target (car this)))
+ (when ,form
+ (return this))))
+ ;; If there is no TEST/TEST-NOT or
+ ;; KEY, do the EQ/EQL test first,
+ ;; before checking for NIL.
+ `(let ((target (car this)))
+ (when (and ,form this)
+ (return this)))))
+ (member
+ `(let ((target this))
(when ,form
- (return this))))
- ;; If there is no TEST/TEST-NOT or
- ;; KEY, do the EQ/EQL test first,
- ;; before checking for NIL.
- `(let ((target (car this)))
- (when (and ,form this)
- (return this)))))
- (member
- `(let ((target this))
- (when ,form
- (return list))))))))))
+ (return list))))
+ (adjoin
+ `(let ((target this))
+ (when ,form
+ (return t))))))))
+ (body (if (eq 'adjoin name)
+ `(if (let ,(when (member 'key funs)
+ `((item (funcall key item))))
+ ,body-loop)
+ list
+ (cons item list))
+ body-loop)))
+ `(defun ,(intern (format nil "%~A~{-~A~}~@[-~A~]" name funs variant))
+ (item list ,@funs)
+ (declare (optimize speed (sb!c::verify-arg-count 0)))
+ ,@(when funs `((declare (function ,@funs))))
+ ,body))))
`(progn
- ,(%def 'member)
- ,(%def 'assoc)))))
+ ,(%def 'adjoin)
+ ,(%def 'assoc)
+ ,(%def 'member)))))
(def ()
(eql item target))
(def ()
(def (test)
(funcall test item target))
(def (test-not)
- (not (funcall test-not item target))))
+ (not (funcall test-not item target))))