1
0
forked from GitHub/gf-core

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.
This commit is contained in:
hallgren
2011-08-30 18:54:50 +00:00
parent 2001788b02
commit ba10b5b0ca
12 changed files with 52 additions and 37 deletions

View File

@@ -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)

View File

@@ -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})

View File

@@ -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