From 85ef506a60f18e6faf878e2722d199bfcefc9e71 Mon Sep 17 00:00:00 2001 From: Jorge Tavares Date: Sun, 7 Mar 2010 19:31:54 +0100 Subject: [PATCH] bug fix: FIND / POSITION on lists signal bounding-indices-bad-error (bug #452008) --- src/compiler/seqtran.lisp | 62 ++++++++++++++++++++++---------------------- 1 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/compiler/seqtran.lisp b/src/compiler/seqtran.lisp index a4717f4..a960a16 100644 --- a/src/compiler/seqtran.lisp +++ b/src/compiler/seqtran.lisp @@ -1199,37 +1199,37 @@ (find nil) (position nil)) (declare (type index index)) - (dolist (i sequence - (if (and end (> end index)) - (sequence-bounding-indices-bad-error - sequence start end) - (values find position))) - (when (and end (>= index end)) - (return (values find position))) - (when (>= index start) - (let ((key-i (funcall key i))) - (,',condition (funcall predicate key-i) - ;; This hack of dealing with non-NIL - ;; FROM-END for list data by iterating - ;; forward through the list and keeping - ;; track of the last time we found a - ;; match might be more screwy than what - ;; the user expects, but it seems to be - ;; allowed by the ANSI standard. (And - ;; if the user is screwy enough to ask - ;; for FROM-END behavior on list data, - ;; turnabout is fair play.) - ;; - ;; It's also not enormously efficient, - ;; calling PREDICATE and KEY more often - ;; than necessary; but all the - ;; alternatives seem to have their own - ;; efficiency problems. - (if from-end - (setf find i - position index) - (return (values i index)))))) - (incf index)))))) + (if (and end (or (> start end) + (> end (length sequence)))) + (sequence-bounding-indices-bad-error + sequence start end) + (dolist (i sequence (values find position)) + (when (and end (>= index end)) + (return (values find position))) + (when (>= index start) + (let ((key-i (funcall key i))) + (,',condition (funcall predicate key-i) + ;; This hack of dealing with non-NIL + ;; FROM-END for list data by iterating + ;; forward through the list and keeping + ;; track of the last time we found a + ;; match might be more screwy than what + ;; the user expects, but it seems to be + ;; allowed by the ANSI standard. (And + ;; if the user is screwy enough to ask + ;; for FROM-END behavior on list data, + ;; turnabout is fair play.) + ;; + ;; It's also not enormously efficient, + ;; calling PREDICATE and KEY more often + ;; than necessary; but all the + ;; alternatives seem to have their own + ;; efficiency problems. + (if from-end + (setf find i + position index) + (return (values i index)))))) + (incf index))))))) (def %find-position-if when) (def %find-position-if-not unless)) -- 1.6.5.7