on master help sign in
Make encoding slightly faster.

The improvement mainly comes from dropping a redundant check when decoding an ASCII byte.

commit7679113c8d232d36b4a14ae47b01bd72d13795ec authorBryan O'Sullivan <bos@serpentine.com> dateThu 22 Dec 2011, 23:53 (15 years ago) parent049278d
1 file changed+2−4
Data/Text/Encoding.hs+2−4
Data/Text/Encoding.hs+2−4
@@ -154,7 +154,7 @@ encodeUtf8 (Text arr off len) = unsafePerformIO $ do
154154 loop n1 m1 ptr = go n1 m1
155155 where
156156 go !n !m
157− | n-off == len = return (PS fp 0 m)
157+ | n == off+len = return (PS fp 0 m)
158158 | otherwise = do
159159 let poke8 k v = poke (ptr `plusPtr` k) (fromIntegral v :: Word8)
160160 ensure k act
@@ -167,9 +167,7 @@ encodeUtf8 (Text arr off len) = unsafePerformIO $ do
167167 start newSize n m fp'
168168 {-# INLINE ensure #-}
169169 case A.unsafeIndex arr n of
170− w| w <= 0x7F -> ensure 1 $ do
171− poke8 m w
172− go (n+1) (m+1)
170+ w| w <= 0x7F -> poke8 m w >> go (n+1) (m+1)
173171 | w <= 0x7FF -> ensure 2 $ do
174172 poke8 m $ (w `shiftR` 6) + 0xC0
175173 poke8 (m+1) $ (w .&. 0x3f) + 0x80