Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1306,12 +1306,19 @@ splitAt = loop
loop :: Int64 -> Text -> (Text, Text)
loop !_ Empty = (empty, empty)
loop n t | n <= 0 = (empty, t)
loop n (Chunk t ts)
| n < len = let (t',t'') = T.splitAt (int64ToInt n) t
in (Chunk t' Empty, Chunk t'' ts)
| otherwise = let (ts',ts'') = loop (n - len) ts
loop n (Chunk t@(T.Text arr off len) ts)
| n > mx = let (ts', ts'') = loop (n - intToInt64 (T.length t)) ts
in (Chunk t ts', ts'')
| m > 0, m >= len = (Chunk t Empty, ts)
| m > 0 = let t' = T.Text arr off m
t'' = T.Text arr (off+m) (len-m)
in (Chunk t' Empty, Chunk t'' ts)
| otherwise = let (ts', ts'') = loop (n + intToInt64 m) ts
in (Chunk t ts', ts'')
where len = intToInt64 (T.length t)
where
mx = intToInt64 P.maxBound
m = T.measureOff (int64ToInt n) t


-- | /O(n)/ 'splitAtWord' @n t@ returns a strict pair whose first
-- element is a prefix of @t@ whose chunks contain @n@ 'Word8'
Expand Down