Skip to content

Commit

Permalink
1.0.31.7: transform %FIND-POSITION for strings
Browse files Browse the repository at this point in the history
 * Based on patch by Karol Swietlicki.

   https://bugs.launchpad.net/sbcl/+bug/410122
  • Loading branch information
nikodemus committed Sep 13, 2009
1 parent 386781e commit 70b3929
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
6 changes: 4 additions & 2 deletions NEWS
@@ -1,13 +1,15 @@
;;;; -*- coding: utf-8; fill-column: 78 -*-
changes relative to sbcl-1.0.31
* optimization: faster FIND and POSITION on strings of unknown element type
in high SPEED policies. (thanks to Karol Swietlicki)
* improvement: better error signalling for bogus parameter specializer names
in DEFMETHOD forms (reported by Pluijzer)
* bug fix: SAVE-LISP-AND-DIE option :SAVE-RUNTIME-OPTIONS did not work
correctly when starting from an executable core without saved runtime
options (reported by Faré Rideau, thanks to Zach Beane)
* bug fix: (SETF SLOT-VALUE) signalled a warning which should have been
an optimization note instead. (reported by Martin Cracauer)
* bug fix: WITH-SLOTS did not work with THE forms. (thanks to David Tolpin)
* improvement: better error signalling for bogus parameter specializer names
in DEFMETHOD forms (reported by Pluijzer)

changes in sbcl-1.0.31 relative to sbcl-1.0.30:
* improvement: stack allocation is should now be possible in all nested
Expand Down
4 changes: 3 additions & 1 deletion src/code/primordial-extensions.lisp
Expand Up @@ -145,7 +145,9 @@
(declare (inline ,fun))
(etypecase ,var
,@(loop for type in types
collect `(,type (,fun (the ,type ,var))))))))
;; TRULY-THE allows transforms to take advantage of the type
;; information without need for constraint propagation.
collect `(,type (,fun (truly-the ,type ,var))))))))

;;; Automate an idiom often found in macros:
;;; (LET ((FOO (GENSYM "FOO"))
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/array-tran.lisp
Expand Up @@ -17,13 +17,15 @@
;;; GIVE-UP-IR1-TRANSFORM if the upgraded element type can't be
;;; determined.
(defun upgraded-element-type-specifier-or-give-up (lvar)
(let* ((element-ctype (extract-upgraded-element-type lvar))
(element-type-specifier (type-specifier element-ctype)))
(let ((element-type-specifier (upgraded-element-type-specifier lvar)))
(if (eq element-type-specifier '*)
(give-up-ir1-transform
"upgraded array element type not known at compile time")
element-type-specifier)))

(defun upgraded-element-type-specifier (lvar)
(type-specifier (extract-upgraded-element-type lvar)))

;;; Array access functions return an object from the array, hence its type is
;;; going to be the array upgraded element type. Secondary return value is the
;;; known supertype of the upgraded-array-element-type, if if the exact
Expand Down
24 changes: 24 additions & 0 deletions src/compiler/seqtran.lisp
Expand Up @@ -1351,6 +1351,30 @@
'(%find-position-vector-macro item sequence
from-end start end key test))

(deftransform %find-position ((item sequence from-end start end key test)
(character string t t t function function)
*
:policy (> speed space))
(if (eq '* (upgraded-element-type-specifier sequence))
(let ((form
`(sb!impl::string-dispatch ((simple-array character (*))
(simple-array base-char (*))
(simple-array nil (*)))
sequence
(%find-position item sequence from-end start end key test))))
(if (csubtypep (lvar-type sequence) (specifier-type 'simple-string))
form
;; Otherwise we'd get three instances of WITH-ARRAY-DATA from
;; %FIND-POSITION.
`(with-array-data ((sequence sequence :offset-var offset)
(start start)
(end end)
:check-fill-pointer t)
(multiple-value-bind (elt index) ,form
(values elt (when (fixnump index) (- index offset)))))))
;; The type is known exactly, other transforms will take care of it.
(give-up-ir1-transform)))

;;; logic to unravel :TEST, :TEST-NOT, and :KEY options in FIND,
;;; POSITION-IF, etc.
(define-source-transform effective-find-position-test (test test-not)
Expand Down
2 changes: 1 addition & 1 deletion version.lisp-expr
Expand Up @@ -17,4 +17,4 @@
;;; checkins which aren't released. (And occasionally for internal
;;; versions, especially for internal versions off the main CVS
;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
"1.0.31.6"
"1.0.31.7"

0 comments on commit 70b3929

Please sign in to comment.