From ba10b5b0ca0c906b1b5c94f64b37b5a34f200f71 Mon Sep 17 00:00:00 2001 From: hallgren Date: Tue, 30 Aug 2011 18:54:50 +0000 Subject: GF.Infra.Modules: keep the modules of a grammar in a finite map instead of a list This speeds up the compilation of PhrasebookFin.pgf by 12%, mosly by speeding up calls to lookupModule in calls from lookupParamValues, in calls from allParamValues. The invariant "modules are stored in dependency order" is no longer respected! But the type MGrammar is now abstract, making it easier to maintain this or other invariants in the future. --- src/compiler/GF/Grammar/Binary.hs | 4 ++-- src/compiler/GF/Grammar/CF.hs | 2 +- src/compiler/GF/Grammar/Grammar.hs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/compiler/GF/Grammar') diff --git a/src/compiler/GF/Grammar/Binary.hs b/src/compiler/GF/Grammar/Binary.hs index 0cee6f2c6..32ddfe6ad 100644 --- a/src/compiler/GF/Grammar/Binary.hs +++ b/src/compiler/GF/Grammar/Binary.hs @@ -27,8 +27,8 @@ instance Binary Ident where else return (identC bs) instance Binary a => Binary (MGrammar a) where - put (MGrammar ms) = put ms - get = fmap MGrammar get + put = put . modules + get = fmap mGrammar get instance Binary a => Binary (ModInfo a) where put mi = do put (mtype mi,mstatus mi,flags mi,extend mi,mwith mi,opens mi,mexdeps mi,jments mi) diff --git a/src/compiler/GF/Grammar/CF.hs b/src/compiler/GF/Grammar/CF.hs index 009bbd3c2..93ae10b4a 100644 --- a/src/compiler/GF/Grammar/CF.hs +++ b/src/compiler/GF/Grammar/CF.hs @@ -81,7 +81,7 @@ type CFFun = String -------------------------- cf2gf :: String -> CF -> SourceGrammar -cf2gf name cf = MGrammar [ +cf2gf name cf = mGrammar [ (aname, addFlag (modifyFlags (\fs -> fs{optStartCat = Just cat})) (emptyModInfo{mtype = MTAbstract, jments = abs})), (cname, emptyModInfo{mtype = MTConcrete aname, jments = cnc}) diff --git a/src/compiler/GF/Grammar/Grammar.hs b/src/compiler/GF/Grammar/Grammar.hs index f99ed0414..e29bc331a 100644 --- a/src/compiler/GF/Grammar/Grammar.hs +++ b/src/compiler/GF/Grammar/Grammar.hs @@ -15,7 +15,7 @@ ----------------------------------------------------------------------------- module GF.Grammar.Grammar (SourceGrammar, - emptySourceGrammar, + emptySourceGrammar,mGrammar, SourceModInfo, SourceModule, mapSourceModule, @@ -56,7 +56,7 @@ import qualified Data.ByteString.Char8 as BS -- | grammar as presented to the compiler type SourceGrammar = MGrammar Info -emptySourceGrammar = MGrammar [] +emptySourceGrammar = mGrammar [] type SourceModInfo = ModInfo Info -- cgit v1.2.3