1 ! Copyright (C) 2004, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel math strings 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 [ >fixnum ] [ >fixnum ] [ underlying>> ] tri* set-string-nth ;
17 drop [ 0 <string> ] [ >fixnum ] bi sbuf boa ;
19 : >sbuf ( seq -- sbuf ) SBUF" " clone-like ; inline
23 dup string? [ dup length sbuf boa ] [ >sbuf ] if
26 M: sbuf new-resizable drop <sbuf> ;
29 over sbuf? [ sequence= ] [ 2drop f ] if ;
31 M: string new-resizable drop <sbuf> ;
34 #! If we have a string, we're done.
35 #! If we have an sbuf, and it's at full capacity, we're done.
36 #! Otherwise, call resize-string, which is a relatively
40 [ length ] [ underlying>> ] bi
42 [ nip dup reset-string-hashcode ] [ resize-string ] if
46 INSTANCE: sbuf growable