|
From: William H. N. <wil...@ai...> - 2003-05-07 02:09:27
|
On Tue, May 06, 2003 at 11:26:34PM +0200, Pascal Bourguignon wrote:
>
> What declarations are needed to compile this without type uncertainty?
>
> (DEFUN COPY (SRC FROM-SRC DST FROM-DST LENGTH)
> (DECLARE (STRING SRC DST) (FIXNUM FROM-SRC FROM-DST LENGTH))
> (WHILE (< 0 LENGTH)
> (SETF (CHAR DST FROM-DST) (CHAR SRC FROM-SRC))
> (INCF FROM-DST)
> (INCF FROM-SRC)
> (DECF LENGTH))
> ) ;;COPY
> ; --> MULTIPLE-VALUE-BIND MULTIPLE-VALUE-CALL
> ; ==>
> ; (SB-KERNEL:%DATA-VECTOR-AND-INDEX ARRAY SB-INT:INDEX)
> ;
> ; note: unable to
> ; optimize
> ; due to type uncertainty:
> ; The first argument is a BASE-STRING, not a SIMPLE-ARRAY.
If you can declare SRC and DST to be SIMPLE-STRING, then the code
can be compiled most efficiently, and the notes should go away.
If you don't *want* SRC and DST to be SIMPLE-STRINGs -- perhaps
because you want FILL-POINTERs or something -- then there may be no
completely satisfactory way to get rid of the optimization note. You
could use SB-EXT:INHIBIT-WARNINGS, but that affects an entire region
of code, not just a particular property of a particular symbol.
> (Typical usage of COPY would be:
> (let ((dst (make-string 10)))
> (copy "hello" 0 dst 0 5)
> (copy "world" 0 dst 5 5)
> dst)
> )
You might also be able to use the standard operator CL:REPLACE for this.
(let ((dst (make-string 10)))
(replace dst "hello")
(replace dst "world" :start1 5)
dst)
--
William Harold Newman <wil...@ai...>
"Don't you *want* SRC and DST to be SIMPLE-STRINGs? I could compile
it so efficiently. Couldn't you think about it a bit more? It might be
very nice if they could be SIMPLE-STRINGs. It would be efficient."
-- Python, trying to be helpful
PGP key fingerprint 85 CE 1C BA 79 8D 51 8C B9 25 FB EE E0 C3 E5 7C
|