Skip to content

Commit aedfe3f

Browse files
committed
Make index middle-lazy
`index` should not descend the finger tree spine unless it needs to.
1 parent c138008 commit aedfe3f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Data/Sequence.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,14 +1159,14 @@ data Place a = Place {-# UNPACK #-} !Int a
11591159
lookupTree :: Sized a => Int -> FingerTree a -> Place a
11601160
lookupTree _ Empty = error "lookupTree of empty tree"
11611161
lookupTree i (Single x) = Place i x
1162-
lookupTree i (Deep _ pr m sf)
1162+
lookupTree i (Deep totalSize pr m sf)
11631163
| i < spr = lookupDigit i pr
11641164
| i < spm = case lookupTree (i - spr) m of
11651165
Place i' xs -> lookupNode i' xs
11661166
| otherwise = lookupDigit (i - spm) sf
11671167
where
11681168
spr = size pr
1169-
spm = spr + size m
1169+
spm = totalSize - size sf
11701170

11711171
{-# SPECIALIZE lookupNode :: Int -> Node (Elem a) -> Place (Elem a) #-}
11721172
{-# SPECIALIZE lookupNode :: Int -> Node (Node a) -> Place (Node a) #-}

0 commit comments

Comments
 (0)