Commits

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.

  • Participants
  • Parent commits b131b42

Comments (0)

Files changed (1)

File 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