on master help sign in
Drop some special-casing for ASCII during UTF-8 encoding

I somehow forgot that we allocate the initial ByteString to contain the same number of bytes as the Text contains code units. This means that we never need to ensure that the ByteString is big enough, nor (with this observation) does a special-cased ASCII-only loop help performance.

commit0f3435bad4f68725c12a70695ae0beac40d8efce authorBryan O'Sullivan <bos@serpentine.com> dateThu 2 Jan 2014, 16:55 (13 years ago) parent08b39b5
1 file changed+2−13
Data/Text/Encoding.hs+2−13
Data/Text/Encoding.hs+2−13
@@ -384,20 +384,9 @@ encodeUtf8 (Text arr off len) = unsafeDupablePerformIO $ do
384384 start newSize n m fp'
385385 {-# INLINE ensure #-}
386386 case A.unsafeIndex arr n of
387− w| w <= 0x7F -> ensure 1 $ do
387+ w| w <= 0x7F -> do
388388 poke (ptr `plusPtr` m) (fromIntegral w :: Word8)
389− -- A single ASCII octet is likely to start a run of
390− -- them. We see better performance when we
391− -- special-case this assumption.
392− let end = ptr `plusPtr` size
393− ascii !t !u
394− | t == offLen || u == end || v >= 0x80 =
395− go t (u `minusPtr` ptr)
396− | otherwise = do
397− poke u (fromIntegral v :: Word8)
398− ascii (t+1) (u `plusPtr` 1)
399− where v = A.unsafeIndex arr t
400− ascii (n+1) (ptr `plusPtr` (m+1))
389+ go (n+1) (m+1)
401390 | w <= 0x7FF -> ensure 2 $ do
402391 poke8 m $ (w `shiftR` 6) + 0xC0
403392 poke8 (m+1) $ (w .&. 0x3f) + 0x80