From a0ed945836880f40bf85161ca17f0bd4240169a7 Mon Sep 17 00:00:00 2001 From: "Gregory W. Schwartz" Date: Wed, 14 Aug 2019 14:32:43 -0400 Subject: [PATCH] Replace insert with alter to bypass extra lookup. --- src/Data/Sparse/Internal/IntMap2.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Data/Sparse/Internal/IntMap2.hs b/src/Data/Sparse/Internal/IntMap2.hs index 5579d83..264cf6c 100644 --- a/src/Data/Sparse/Internal/IntMap2.hs +++ b/src/Data/Sparse/Internal/IntMap2.hs @@ -21,9 +21,10 @@ import GHC.Exts -- IM.Key -> IM.Key -> a -> IM.IntMap (IM.IntMap a) -> IM.IntMap (IM.IntMap a) insertIM2 :: IM.Key -> IM.Key -> a -> I.IntM (I.IntM a) -> I.IntM (I.IntM a) -insertIM2 i j x imm = I.insert i ro imm where - ro = maybe (I.singleton j x) (I.insert j x) (I.lookup i imm) -{-# inline insertIM2 #-} +insertIM2 i j x (I.IntM imm) = I.IntM $ IM.alter ro i imm where + ro Nothing = Just $ I.singleton j x + ro (Just m) = Just $ I.insert j x m +{-# inline insertIM2 #-} -- * Lookup