Commits

Bryan O'Sullivan committed cac7dbc

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!

Comments (0)

Files changed (1)

Data/Text/Encoding.hs

 -- | 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
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.