Bryan O'Sullivan avatar Bryan O'Sullivan committed 8c564eb

Drop the Builder-based encodeUtf8 implementation

While it is very cool indeed, it is slower than the new C code under
all circumstances, sometimes by a factor of two or more.

Comments (0)

Files changed (1)

Data/Text/Encoding.hs

 decodeUtf8' = unsafeDupablePerformIO . try . evaluate . decodeUtf8With strictDecode
 {-# INLINE decodeUtf8' #-}
 
--- | Encode text using UTF-8 encoding.
-encodeUtf8 :: Text -> ByteString
 #if MIN_VERSION_bytestring(0,10,4)
 
-encodeUtf8 t@(Text _arr _off len) =
-      B.copy       -- copy to trim and avoid wasting memory
-    $ BL.toStrict
-    $ B.toLazyByteStringWith strategy BL.empty
-    $ encodeUtf8Builder t
-  where
-    -- We use a strategy that allocates a buffer that is guaranteed to be
-    -- large enough for the whole result. This ensures that we always stay in
-    -- the fast 'goPartial' loop in the 'encodeUtf8BuilderEscaped' function.
-    strategy = B.untrimmedStrategy (4 * (len + 1)) B.defaultChunkSize
-
-
 -- | Encode text to a ByteString 'B.Builder' using UTF-8 encoding.
 encodeUtf8Builder :: Text -> B.Builder
 encodeUtf8Builder = encodeUtf8BuilderEscaped (BP.liftFixedToBounded BP.word8)
                       outerLoop i (B.BufferRange op ope)
                   where
                     poke8 j v = poke (op `plusPtr` j) (fromIntegral v :: Word8)
+#endif
 
-#else
-
+-- | Encode text using UTF-8 encoding.
+encodeUtf8 :: Text -> ByteString
 encodeUtf8 = encodeUtf8_0
 
-#endif
-
 encodeUtf8_0 :: Text -> ByteString
 encodeUtf8_0 (Text arr off len) = unsafeDupablePerformIO $ do
   let size0 = max len 4
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.