File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -1306,12 +1306,18 @@ splitAt = loop
13061306 loop :: Int64 -> Text -> (Text , Text )
13071307 loop ! _ Empty = (empty, empty)
13081308 loop n t | n <= 0 = (empty, t)
1309- loop n (Chunk t ts)
1310- | n < len = let (t',t'') = T. splitAt (int64ToInt n) t
1311- in (Chunk t' Empty , Chunk t'' ts)
1312- | otherwise = let (ts',ts'') = loop (n - len) ts
1309+ loop n (Chunk t@ (T. Text arr off len) ts)
1310+ | m > 0 , m >= len = (Chunk t Empty , ts)
1311+ | m > 0 = let t' = T. Text arr off m
1312+ t'' = T. Text arr (off+ m) (len- m)
1313+ in (Chunk t' Empty , Chunk t'' ts)
1314+ | otherwise = let (ts', ts'') = loop (n + intToInt64 m) ts
13131315 in (Chunk t ts', ts'')
1314- where len = intToInt64 (T. length t)
1316+ where
1317+ k | n > intToInt64 len = len+ 1
1318+ | otherwise = int64ToInt n
1319+ m = T. measureOff k t
1320+
13151321
13161322-- | /O(n)/ 'splitAtWord' @n t@ returns a strict pair whose first
13171323-- element is a prefix of @t@ whose chunks contain @n@ 'Word8'
You can’t perform that action at this time.
0 commit comments