[commit: packages/containers] cleaned_bugfix394, master, merge-doc-target, merge-fixes-5.9, merge-restrict-fix-5.8, revert-408-bugfix_394: Stop fearing the middle (5b589cc)

git at git.haskell.org git at git.haskell.org
Mon Apr 17 21:42:01 UTC 2017


Repository : ssh://git@git.haskell.org/containers

On branches: cleaned_bugfix394,master,merge-doc-target,merge-fixes-5.9,merge-restrict-fix-5.8,revert-408-bugfix_394
Link       : http://git.haskell.org/packages/containers.git/commitdiff/5b589cc61cc5beca55373c8d3d6700ff18fe6b71

>---------------------------------------------------------------

commit 5b589cc61cc5beca55373c8d3d6700ff18fe6b71
Author: David Feuer <David.Feuer at gmail.com>
Date:   Sun May 22 22:33:39 2016 -0400

    Stop fearing the middle
    
    A couple years ago I thought it *must* be a good idea to ever look down
    the middle if it could possibly be avoided, but I never had any
    benchmarks to support it, and it seems pretty silly in retrospect.
    Reverting pending some numbers demonstrating it's really the way to go.


>---------------------------------------------------------------

5b589cc61cc5beca55373c8d3d6700ff18fe6b71
 Data/Sequence.hs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Data/Sequence.hs b/Data/Sequence.hs
index 0f1f2ec..00b1d2b 100644
--- a/Data/Sequence.hs
+++ b/Data/Sequence.hs
@@ -1584,14 +1584,14 @@ data Place a = Place {-# UNPACK #-} !Int a
 lookupTree :: Sized a => Int -> FingerTree a -> Place a
 lookupTree _ EmptyT = error "lookupTree of empty tree"
 lookupTree i (Single x) = Place i x
-lookupTree i (Deep totalSize pr m sf)
+lookupTree i (Deep _ pr m sf)
   | i < spr     =  lookupDigit i pr
   | i < spm     =  case lookupTree (i - spr) m of
                    Place i' xs -> lookupNode i' xs
   | otherwise   =  lookupDigit (i - spm) sf
   where
     spr     = size pr
-    spm     = totalSize - size sf
+    spm     = spr + size m
 
 {-# SPECIALIZE lookupNode :: Int -> Node (Elem a) -> Place (Elem a) #-}
 {-# SPECIALIZE lookupNode :: Int -> Node (Node a) -> Place (Node a) #-}
@@ -1721,7 +1721,7 @@ mapWithIndex f' (Seq xs') = Seq $ mapWithIndexTree (\s (Elem a) -> Elem (f' s a)
                (mapWithIndexDigit f sPsprm sf)
     where
       !sPspr = s + size pr
-      !sPsprm = s + n - size sf
+      !sPsprm = sPspr + size m
 
   {-# SPECIALIZE mapWithIndexDigit :: (Int -> Elem y -> b) -> Int -> Digit (Elem y) -> Digit b #-}
   {-# SPECIALIZE mapWithIndexDigit :: (Int -> Node y -> b) -> Int -> Digit (Node y) -> Digit b #-}



More information about the ghc-commits mailing list