diff --git a/src/compiler/GF/Grammar/Grammar.hs b/src/compiler/GF/Grammar/Grammar.hs index 587b09a9f..448fa1657 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,20 @@ 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 -> 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)