Skip to content

Commit 833ed24

Browse files
committed
fixup! Avoid per-byte loop in cstring{,Utf8} builders
Review feedback
1 parent 395092a commit 833ed24

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Data/ByteString/Builder/Internal.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module Data.ByteString.Builder.Internal (
9090

9191
, byteStringCopy
9292
, asciiLiteralCopy
93-
, modUtf8LitCopy
93+
, modUtf8LiteralCopy
9494
, byteStringInsert
9595
, byteStringThreshold
9696

@@ -997,16 +997,16 @@ asciiLiteralCopy = \ !ip !len -> builder $ \k br@(BufferRange op ope) ->
997997
-- result is not well defined.
998998
--
999999
-- @since 0.13.0.0
1000-
{-# INLINABLE modUtf8LitCopy #-}
1001-
modUtf8LitCopy :: Ptr Word8 -> Int -> Builder
1002-
modUtf8LitCopy !ip !len
1000+
{-# INLINABLE modUtf8LiteralCopy #-}
1001+
modUtf8LiteralCopy :: Ptr Word8 -> Int -> Builder
1002+
modUtf8LiteralCopy !ip !len
10031003
| len > 0 = builder (modUtf8_step ip len)
10041004
| otherwise = builder id
10051005

1006-
-- | Copy a /non-empty/ UTF-8 input possibly containing denormalised 2-octet
1006+
-- | Copy a /non-empty/ UTF-8 input possibly containing overlong 2-octet
10071007
-- sequences. While only the NUL byte should ever encoded that way (as @0xC0
1008-
-- 80@), this handles other denormalised @0xC0 0x??@ sequences by keeping the
1009-
-- bottom 6 bits of the second byte. If the input is non-UTF8 garbage, the the
1008+
-- 80@), this handles other overlong @0xC0 0x??@ sequences by keeping the
1009+
-- bottom 6 bits of the second byte. If the input is non-UTF8 garbage, the
10101010
-- result may not be what the user expected.
10111011
--
10121012
modUtf8_step :: Ptr Word8 -> Int -> BuildStep r -> BuildStep r

Data/ByteString/Builder/Prim.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ cstring s = asciiLiteralCopy (Ptr s) (S.byteCountLiteral s)
671671
--
672672
-- @since 0.11.0.0
673673
cstringUtf8 :: Addr# -> Builder
674-
cstringUtf8 s = modUtf8LitCopy (Ptr s) (S.byteCountLiteral s)
674+
cstringUtf8 s = modUtf8LiteralCopy (Ptr s) (S.byteCountLiteral s)
675675
{-# INLINE cstringUtf8 #-}
676676

677677
------------------------------------------------------------------------------

tests/builder/Data/ByteString/Builder/Prim/Tests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ testCString = testProperty "cstring" $
3737
LC.pack "hello" `L.append` L.singleton 0x20 `L.append` LC.pack "world!"
3838

3939
testCStringUtf8 :: Int -> TestTree
40-
testCStringUtf8 sz = testProperty "cstringUtf8" $
40+
testCStringUtf8 sz = testProperty ("cstringUtf8 (chunk size " ++ shows sz ")") $
4141
BE.toLazyByteStringWith (BE.untrimmedStrategy sz sz) L.empty
4242
(BP.cstringUtf8 "hello\xc0\x80\xc0\x80\xd0\xbc\xd0\xb8\xd1\x80\xc0\x80\xC0"#) ==
4343
LC.pack "hello" `L.append` L.singleton 0x00

0 commit comments

Comments
 (0)