From 3cd426802c5f093d8d07042b9f180e38b8631c0b Mon Sep 17 00:00:00 2001 From: Jan Moringen Date: Mon, 4 Mar 2013 11:26:35 +0100 Subject: [PATCH] Remove redundant LENGTH calls in NSUBSTITUTE[-IF[-NOT]] NSUBSTITUTE, NSUBSTITUTE-IF and NSUBSTITUTE-IF used to contain (let ((length (length sequence))) ... in the code path for lists. In the macroexpansion it became clear that this recomputed and shadowed the LENGTH variables already established by DEFINE-SEQUENCE-TRAVERSER. A very brief test with list lengths between 5 and 500 suggests that the speedup produced by removing the redundant computation can be around 5 to 20 %. --- src/code/seq.lisp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/code/seq.lisp b/src/code/seq.lisp index ea6fda7..8725876 100644 --- a/src/code/seq.lisp +++ b/src/code/seq.lisp @@ -2082,11 +2082,10 @@ many elements are copied." (let ((end (or end length))) (seq-dispatch sequence (if from-end - (let ((length (length sequence))) - (nreverse (nlist-substitute* - new old (nreverse (the list sequence)) - test test-not (- length end) (- length start) - count key))) + (nreverse (nlist-substitute* + new old (nreverse (the list sequence)) + test test-not (- length end) (- length start) + count key)) (nlist-substitute* new old sequence test test-not start end count key)) (if from-end @@ -2136,10 +2135,9 @@ many elements are copied." (declare (fixnum end)) (seq-dispatch sequence (if from-end - (let ((length (length sequence))) - (nreverse (nlist-substitute-if* - new predicate (nreverse (the list sequence)) - (- length end) (- length start) count key))) + (nreverse (nlist-substitute-if* + new predicate (nreverse (the list sequence)) + (- length end) (- length start) count key)) (nlist-substitute-if* new predicate sequence start end count key)) (if from-end @@ -2178,10 +2176,9 @@ many elements are copied." (declare (fixnum end)) (seq-dispatch sequence (if from-end - (let ((length (length sequence))) - (nreverse (nlist-substitute-if-not* - new predicate (nreverse (the list sequence)) - (- length end) (- length start) count key))) + (nreverse (nlist-substitute-if-not* + new predicate (nreverse (the list sequence)) + (- length end) (- length start) count key)) (nlist-substitute-if-not* new predicate sequence start end count key)) (if from-end -- 1.7.10.4