Skip to content

Commit c41cd01

Browse files
Fix an array under-alloc bug in unsafeFromChars
1 parent 1fbba50 commit c41cd01

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • core/src/Streamly/Internal/FileSystem/Path

‎core/src/Streamly/Internal/FileSystem/Path/Common.hs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,10 @@ unsafeFromChars :: (Unbox a) =>
13371337
-> Stream Identity Char
13381338
-> Array a
13391339
unsafeFromChars encode s =
1340-
let n = runIdentity $ Stream.fold Fold.length s
1340+
-- The encoded array may be longer than the char count. We are encoding it
1341+
-- twice, but it may still be cheaper than reallocating the array or
1342+
-- oversizing the array.
1343+
let n = runIdentity $ Stream.fold Fold.length (encode s)
13411344
in Array.fromPureStreamN n (encode s)
13421345

13431346
-- XXX Writing a custom fold for parsing a Posix path may be better for

0 commit comments

Comments
 (0)