summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Källberg <anka.213@gmail.com>2022-10-02 21:49:56 +0200
committerAndreas Källberg <anka.213@gmail.com>2022-10-04 17:01:47 +0200
commitfef7b80d8e988f6ad8de720a9e3a1098bc5f8a3a (patch)
tree24eff0b33289dae2d8af307442205f433faf12d2
parent3122590e351f769ca6e60dfd4eeaafba1c5c22e8 (diff)
Use a Set in isInherited to speed up long extend lists
Now the time is O(log(n)*m) instead of O(n*m) where n is the number of items in the extend list e.g. abstract FromWordNet = WordNet [ a_couple_Card, a_la_carte_Adv, a_la_mode_Adv, a_little_Card, ... ];
-rw-r--r--src/compiler/GF/Grammar/Grammar.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/compiler/GF/Grammar/Grammar.hs b/src/compiler/GF/Grammar/Grammar.hs
index 587b09a9f..8b88561d2 100644
--- a/src/compiler/GF/Grammar/Grammar.hs
+++ b/src/compiler/GF/Grammar/Grammar.hs
@@ -78,6 +78,7 @@ import PGF.Internal (FId, FunId, SeqId, LIndex, Sequence, BindType(..))
import Data.Array.IArray(Array)
import Data.Array.Unboxed(UArray)
import qualified Data.Map as Map
+import qualified Data.Set as Set
import GF.Text.Pretty
@@ -125,10 +126,12 @@ extends :: ModuleInfo -> [ModuleName]
extends = map fst . mextend
isInherited :: MInclude -> Ident -> Bool
-isInherited c i = case c of
- MIAll -> True
- MIOnly is -> elem i is
- MIExcept is -> notElem i is
+isInherited c =
+ case c of
+ MIAll -> const True
+ MIOnly is -> let is' = Set.fromList is in (`Set.member` is')
+ MIExcept is -> let is' = Set.fromList is in (`Set.notMember` is')
+
inheritAll :: ModuleName -> (ModuleName,MInclude)
inheritAll i = (i,MIAll)