io.encodings: a bit faster and make ascii support slices.

locals-and-roots
John Benediktsson 2016-04-07 12:32:05 -07:00
parent 0988df1e5a
commit 6d417f4f71
3 changed files with 37 additions and 16 deletions

View File

@ -14,9 +14,12 @@ M: ascii encode-char
GENERIC: ascii> ( string -- byte-array ) GENERIC: ascii> ( string -- byte-array )
M: object ascii>
[ dup 127 <= [ encode-error ] unless ] B{ } map-as ; inline
M: string ascii> M: string ascii>
dup aux>> dup aux>>
[ [ dup 127 <= [ encode-error ] unless ] B{ } map-as ] [ call-next-method ]
[ string>byte-array-fast ] if ; inline [ string>byte-array-fast ] if ; inline
PRIVATE> PRIVATE>

View File

@ -114,17 +114,29 @@ M: utf16le encode-char ( char stream encoding -- )
: ascii-string>utf16be ( string stream -- ) : ascii-string>utf16be ( string stream -- )
[ 1 swap ascii-string>utf16-byte-array ] dip stream-write ; inline [ 1 swap ascii-string>utf16-byte-array ] dip stream-write ; inline
M: utf16le encode-string GENERIC# encode-string-utf16le 1 ( string stream -- )
drop
over dup string? [ aux>> ] [ drop t ] if
[ [ char>utf16le ] curry each ]
[ ascii-string>utf16le ] if ;
M: utf16be encode-string M: object encode-string-utf16le
drop [ char>utf16le ] curry each ; inline
over dup string? [ aux>> ] [ drop t ] if
[ [ char>utf16be ] curry each ] M: string encode-string-utf16le
[ ascii-string>utf16be ] if ; over aux>>
[ call-next-method ]
[ ascii-string>utf16le ] if ; inline
M: utf16le encode-string drop encode-string-utf16le ;
GENERIC# encode-string-utf16be 1 ( string stream -- )
M: object encode-string-utf16be
[ char>utf16be ] curry each ; inline
M: string encode-string-utf16be
over aux>>
[ call-next-method ]
[ ascii-string>utf16be ] if ; inline
M: utf16be encode-string drop encode-string-utf16be ;
M: utf16le guess-encoded-length drop 2 * ; inline M: utf16le guess-encoded-length drop 2 * ; inline
M: utf16le guess-decoded-length drop 2 /i ; inline M: utf16le guess-decoded-length drop 2 /i ; inline

View File

@ -84,11 +84,17 @@ M: utf8 decode-until (decode-until) ;
M: utf8 encode-char M: utf8 encode-char
drop char>utf8 ; drop char>utf8 ;
M: utf8 encode-string GENERIC# encode-string-utf8 1 ( string stream -- )
drop
over dup string? [ aux>> ] [ drop t ] if M: object encode-string-utf8
[ [ char>utf8 ] curry each ] [ char>utf8 ] curry each ; inline
[ [ string>byte-array-fast ] dip stream-write ] if ;
M: string encode-string-utf8
over aux>>
[ call-next-method ]
[ [ string>byte-array-fast ] dip stream-write ] if ; inline
M: utf8 encode-string drop encode-string-utf8 ;
PRIVATE> PRIVATE>