io.encodings.string: faster decode and encode
stream-contents is apparently way slow for decoders. Write decode out more directly as a read1/push loop so it's faster. encode isn't quite as bad, but we can still get a 25% speed improvement by writing to an appropriately sized byte-vector.db4
parent
ffacdaf0da
commit
5c945595ee
|
@ -1,10 +1,16 @@
|
||||||
! Copyright (C) 2008 Daniel Ehrenberg.
|
! Copyright (C) 2008 Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: io io.streams.byte-array ;
|
USING: byte-vectors io io.encodings io.streams.byte-array
|
||||||
|
io.streams.string kernel locals sbufs sequences ;
|
||||||
IN: io.encodings.string
|
IN: io.encodings.string
|
||||||
|
|
||||||
: decode ( byte-array encoding -- string )
|
:: decode ( byte-array encoding -- string )
|
||||||
<byte-reader> stream-contents ;
|
byte-array encoding <byte-reader> :> reader
|
||||||
|
byte-array length encoding guess-decoded-length <sbuf> :> buf
|
||||||
|
[ reader stream-read1 dup ] [ buf push ] while drop
|
||||||
|
buf "" like ; inline
|
||||||
|
|
||||||
: encode ( string encoding -- byte-array )
|
:: encode ( string encoding -- byte-array )
|
||||||
[ write ] with-byte-writer ;
|
string length encoding guess-encoded-length <byte-vector> :> vec
|
||||||
|
string vec encoding <encoder> stream-write
|
||||||
|
vec B{ } like ; inline
|
||||||
|
|
Loading…
Reference in New Issue