From fef7b80d8e988f6ad8de720a9e3a1098bc5f8a3a Mon Sep 17 00:00:00 2001 From: Andreas Källberg Date: Sun, 2 Oct 2022 21:49:56 +0200 Subject: 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, ... ]; --- src/compiler/GF/Grammar/Grammar.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/compiler/GF') 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) -- cgit v1.2.3