Skip to content

Commit

Permalink
Merge pull request #147 from anka-213/extend-performance-issue
Browse files Browse the repository at this point in the history
Improve performance with long extend-lists
  • Loading branch information
inariksit authored Oct 10, 2022
2 parents 3122590 + a58c6d4 commit 6edd449
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/compiler/GF/Grammar/Grammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6edd449

Please sign in to comment.