1 ! Copyright (C) 2004, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel math sequences.private sequences
4 strings growable strings.private ;
9 { length array-capacity } ;
11 : <sbuf> ( n -- sbuf ) 0 <string> 0 sbuf boa ; inline
13 M: sbuf set-nth-unsafe
14 [ integer>fixnum ] [ integer>fixnum ] [ underlying>> ] tri*
15 set-string-nth ; inline
18 drop [ 0 <string> ] [ integer>fixnum ] bi sbuf boa ; inline
20 : >sbuf ( seq -- sbuf ) SBUF" " clone-like ; inline
22 M: sbuf contract 2drop ; inline
26 dup string? [ dup length sbuf boa ] [ >sbuf ] if
30 over sbuf? [ sequence= ] [ 2drop f ] if ;
32 M: string new-resizable drop <sbuf> ; inline
34 M: sbuf new-resizable drop <sbuf> ; inline
37 #! If we have a string, we're done.
38 #! If we have an sbuf, and it's at full capacity, we're done.
39 #! Otherwise, call resize-string, which is a relatively
43 [ length ] [ underlying>> ] bi
45 [ nip dup reset-string-hashcode ] [ resize-string ] if
49 INSTANCE: sbuf growable