Skip to content

Commit ebb98f3

Browse files
committed
Tweak 888b977
This avoids the shadowing warning and also reduces integer overflowing corner cases.
1 parent 3c64bb0 commit ebb98f3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Data/Text.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,15 +1107,15 @@ replicate n t@(Text a o l)
11071107
| isSingleton t = replicateChar n (unsafeHead t)
11081108
| otherwise = Text (A.run x) 0 len
11091109
where
1110-
len = l `mul` n
1110+
len = l `mul` n -- TODO: detect overflows
11111111
x :: ST s (A.MArray s)
11121112
x = do
11131113
arr <- A.new len
11141114
A.copyI arr 0 a o l
1115-
let loop !l =
1116-
let l2 = l `shiftL` 1 in
1117-
if l2 > len then A.copyM arr l arr 0 (len - l) >> return arr
1118-
else A.copyM arr l arr 0 l >> loop l2
1115+
let loop !l1 =
1116+
let rest = len - l1 in
1117+
if rest <= l1 then A.copyM arr l1 arr 0 rest >> return arr
1118+
else A.copyM arr l1 arr 0 l1 >> loop (l1 `shiftL` 1)
11191119
loop l
11201120
{-# INLINE [1] replicate #-}
11211121

0 commit comments

Comments
 (0)