Skip to content

Commit 0c6b026

Browse files
dolioBodigrim
authored andcommitted
Check for maxBound in lazy splitAt in its own case
1 parent fc86f1c commit 0c6b026

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Data/Text/Lazy.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,16 +1307,17 @@ splitAt = loop
13071307
loop !_ Empty = (empty, empty)
13081308
loop n t | n <= 0 = (empty, t)
13091309
loop n (Chunk t@(T.Text arr off len) ts)
1310+
| n > mx = let (ts', ts'') = loop (n - intToInt64 (T.length t)) ts
1311+
in (Chunk t ts', ts'')
13101312
| m > 0, m >= len = (Chunk t Empty, ts)
13111313
| m > 0 = let t' = T.Text arr off m
13121314
t'' = T.Text arr (off+m) (len-m)
13131315
in (Chunk t' Empty, Chunk t'' ts)
13141316
| otherwise = let (ts', ts'') = loop (n + intToInt64 m) ts
13151317
in (Chunk t ts', ts'')
13161318
where
1317-
k | n > intToInt64 len = len+1
1318-
| otherwise = int64ToInt n
1319-
m = T.measureOff k t
1319+
mx = intToInt64 P.maxBound
1320+
m = T.measureOff (int64ToInt n) t
13201321

13211322

13221323
-- | /O(n)/ 'splitAtWord' @n t@ returns a strict pair whose first

0 commit comments

Comments
 (0)