]> gitweb.factorcode.org Git - factor.git/commitdiff
io.encodings: a bit faster and make ascii support slices.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 7 Apr 2016 19:32:05 +0000 (12:32 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 7 Apr 2016 19:32:05 +0000 (12:32 -0700)
core/io/encodings/ascii/ascii.factor
core/io/encodings/utf16/utf16.factor
core/io/encodings/utf8/utf8.factor

index 2c7a475217c1b2c9d7e15b4b30e1cc11a653cf34..ddb0818c82c9983357acdc5349f8b3eea480aaac 100644 (file)
@@ -14,9 +14,12 @@ M: ascii encode-char
 
 GENERIC: ascii> ( string -- byte-array )
 
+M: object ascii>
+    [ dup 127 <= [ encode-error ] unless ] B{ } map-as ; inline
+
 M: string ascii>
     dup aux>>
-    [ [ dup 127 <= [ encode-error ] unless ] B{ } map-as ]
+    [ call-next-method ]
     [ string>byte-array-fast ] if ; inline
 
 PRIVATE>
index 24491a7a26ce64e118710104241a608a2ab3b5a5..5eba481bd38e2671a1304cc6484d7468123e8eeb 100644 (file)
@@ -114,17 +114,29 @@ M: utf16le encode-char ( char stream encoding -- )
 : ascii-string>utf16be ( string stream -- )
     [ 1 swap ascii-string>utf16-byte-array ] dip stream-write ; inline
 
-M: utf16le encode-string
-    drop
-    over dup string? [ aux>> ] [ drop t ] if
-    [ [ char>utf16le ] curry each ]
-    [ ascii-string>utf16le ] if ;
-
-M: utf16be encode-string
-    drop
-    over dup string? [ aux>> ] [ drop t ] if
-    [ [ char>utf16be ] curry each ]
-    [ ascii-string>utf16be ] if ;
+GENERIC# encode-string-utf16le 1 ( string stream -- )
+
+M: object encode-string-utf16le
+    [ char>utf16le ] curry each ; inline
+
+M: string encode-string-utf16le
+    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-decoded-length drop 2 /i ; inline
index d07893c0efd99f05018ec72d932e8e2c6941ec6b..4979daad15bd1c5b06b289d4a24b568c919a8759 100644 (file)
@@ -84,11 +84,17 @@ M: utf8 decode-until (decode-until) ;
 M: utf8 encode-char
     drop char>utf8 ;
 
-M: utf8 encode-string
-    drop
-    over dup string? [ aux>> ] [ drop t ] if
-    [ [ char>utf8 ] curry each ]
-    [ [ string>byte-array-fast ] dip stream-write ] if ;
+GENERIC# encode-string-utf8 1 ( string stream -- )
+
+M: object encode-string-utf8
+    [ char>utf8 ] curry each ; inline
+
+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>