Skip to content

Commit 202e2f2

Browse files
committed
Merge pull request #118 from treeowl/apcleanup
Clean up <*> development artifacts
2 parents e0cfb50 + f1e0f8e commit 202e2f2

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Data/Sequence.hs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,18 @@ aptyMiddle firstf
341341
(Deep s (squashL pr prm) mm (squashR sfm sf)))
342342
(fmap (fmap lastf) sfm)
343343

344-
-- At the bottom
344+
-- At the bottom. Note that these appendTree0 calls are very cheap, because in
345+
-- each case, one of the arguments is guaranteed to be Empty or Single.
345346
aptyMiddle firstf
346347
lastf
347348
map23
348349
fs
349350
(Deep s pr m sf)
350-
= (fmap (fmap firstf) m `snocTree` fmap firstf (digitToNode sf))
351-
`appendTree0` middle `appendTree0`
352-
(fmap lastf (digitToNode pr) `consTree` fmap (fmap lastf) m)
351+
= fmap (fmap firstf) m `appendTree0`
352+
((fmap firstf (digitToNode sf)
353+
`consTree` middle)
354+
`snocTree` fmap lastf (digitToNode pr))
355+
`appendTree0` fmap (fmap lastf) m
353356
where middle = case trimTree $ mapMulFT s (\(Elem f) -> fmap (fmap (map23 f)) converted) fs of
354357
(firstMapped, restMapped, lastMapped) ->
355358
Deep (size firstMapped + size restMapped + size lastMapped)
@@ -472,17 +475,16 @@ rigidify Single{} = error "rigidify: singleton"
472475
-- | /O(log n)/ (incremental) Rejigger a finger tree so the digits are all ones
473476
-- and twos.
474477
thin :: Sized a => FingerTree a -> FingerTree a
475-
-- Note that 'thin' may call itself at most once before passing the job on to
476-
-- 'thin12'. 'thin12' will produce a 'Deep' constructor immediately before
477-
-- calling 'thin'.
478+
-- Note that 'thin12' will produce a 'Deep' constructor immediately before
479+
-- recursively calling 'thin'.
478480
thin Empty = Empty
479481
thin (Single a) = Single a
480482
thin t@(Deep s pr m sf) =
481483
case pr of
482484
One{} -> thin12 t
483485
Two{} -> thin12 t
484-
Three a b c -> thin $ Deep s (One a) (node2 b c `consTree` m) sf
485-
Four a b c d -> thin $ Deep s (Two a b) (node2 c d `consTree` m) sf
486+
Three a b c -> thin12 $ Deep s (One a) (node2 b c `consTree` m) sf
487+
Four a b c d -> thin12 $ Deep s (Two a b) (node2 c d `consTree` m) sf
486488

487489
thin12 :: Sized a => FingerTree a -> FingerTree a
488490
thin12 (Deep s pr m sf@One{}) = Deep s pr (thin m) sf

0 commit comments

Comments
 (0)