1 ! Copyright (C) 2003, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel math.private sequences kernel.private
4 math sequences.private slots.private byte-arrays
10 : string-hashcode ( str -- n ) 3 slot ; inline
12 : set-string-hashcode ( n str -- ) 3 set-slot ; inline
14 : reset-string-hashcode ( str -- )
15 f swap set-string-hashcode ; inline
17 : rehash-string ( str -- )
18 1 over sequence-hashcode swap set-string-hashcode ; inline
20 : set-string-nth ( ch n str -- )
22 [ set-string-nth-fast ] [ set-string-nth-slow ] if ; inline
28 over hashcode over hashcode eq?
29 [ sequence= ] [ 2drop f ] if
37 [ ] [ dup rehash-string string-hashcode ] ?if ;
43 [ >fixnum ] dip string-nth ;
45 M: string set-nth-unsafe
46 dup reset-string-hashcode
47 [ >fixnum ] [ >fixnum ] [ ] tri* set-string-nth ;
50 (clone) [ clone ] change-aux ;
52 M: string resize resize-string ;
54 : 1string ( ch -- str ) 1 swap <string> ;
56 : >string ( seq -- str ) "" clone-like ;
58 M: string new-sequence drop 0 <string> ;
60 INSTANCE: string sequence