Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Oh noes! I was miscalculating the initial buffer size!

When performance testing encodeUtf8, I noticed that for some reason I
was still seeing "ensure" show up in the profile, when I expected it
shouldn't have been.

Turns out I was using a "min" where I should have been using a "max",
and thus allocating an initial bytestring that would almost always be
too small, thus forcing reallocations and copying. Boo!
  • Loading branch information...
commit 9dec3d6953ea636d206b164946da84f118bea9de 1 parent 4050227
@bos authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  Data/Text/Encoding.hs
View
2  Data/Text/Encoding.hs
@@ -144,7 +144,7 @@ decodeUtf8' = unsafePerformIO . try . evaluate . decodeUtf8With strictDecode
-- | Encode text using UTF-8 encoding.
encodeUtf8 :: Text -> ByteString
encodeUtf8 (Text arr off len) = unsafePerformIO $ do
- let size0 = min len 4
+ let size0 = max len 4
mallocByteString size0 >>= start size0 off 0
where
start size n0 m0 fp = withForeignPtr fp $ loop n0 m0
Please sign in to comment.
Something went wrong with that request. Please try again.