summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Källberg <anka.213@gmail.com>2022-10-02 21:57:11 +0200
committerAndreas Källberg <anka.213@gmail.com>2022-10-04 17:01:47 +0200
commita58c6d49d4b5d5cf750c36c9071279fccd9c468f (patch)
tree8f0549380ca8d4193666668eb59d5f36e8e4793f
parentfef7b80d8e988f6ad8de720a9e3a1098bc5f8a3a (diff)
Extract the previous optimization to its own function
-rw-r--r--src/compiler/GF/Grammar/Grammar.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/compiler/GF/Grammar/Grammar.hs b/src/compiler/GF/Grammar/Grammar.hs
index 8b88561d2..448fa1657 100644
--- a/src/compiler/GF/Grammar/Grammar.hs
+++ b/src/compiler/GF/Grammar/Grammar.hs
@@ -129,9 +129,17 @@ isInherited :: MInclude -> Ident -> Bool
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')
+ MIOnly is -> elemOrd is
+ MIExcept is -> not . elemOrd is
+-- | Faster version of `elem`, using a `Set`.
+-- Make sure you give this the first argument _outside_ of the inner loop
+--
+-- Example:
+-- > myIntersection xs ys = filter (elemOrd xs) ys
+elemOrd :: Ord a => [a] -> a -> Bool
+elemOrd list = (`Set.member` set)
+ where set = Set.fromList list
inheritAll :: ModuleName -> (ModuleName,MInclude)
inheritAll i = (i,MIAll)