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/Compile.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/compiler/GF/Compile.hs') diff --git a/src/compiler/GF/Compile.hs b/src/compiler/GF/Compile.hs index 00b08dbf3..b0c228e53 100644 --- a/src/compiler/GF/Compile.hs +++ b/src/compiler/GF/Compile.hs @@ -69,8 +69,8 @@ batchCompile opts files = do -- to compile a set of modules, e.g. an old GF or a .cf file compileSourceGrammar :: Options -> SourceGrammar -> IOE SourceGrammar -compileSourceGrammar opts gr@(MGrammar ms) = do - (_,gr',_) <- foldM compOne (0,emptySourceGrammar,Map.empty) ms +compileSourceGrammar opts gr = do + (_,gr',_) <- foldM compOne (0,emptySourceGrammar,Map.empty) (modules gr) return gr' where compOne env mo = do @@ -215,19 +215,19 @@ generateModuleCode opts file minfo = do -- auxiliaries -reverseModules (MGrammar ms) = MGrammar $ reverse ms +--reverseModules (MGrammar ms) = MGrammar $ reverse ms emptyCompileEnv :: CompileEnv emptyCompileEnv = (0,emptyMGrammar,Map.empty) -extendCompileEnvInt (_,MGrammar ss,menv) k mfile sm = do +extendCompileEnvInt (_,gr,menv) k mfile sm = do let (mod,imps) = importsOfModule sm menv2 <- case mfile of Just file -> do t <- ioeIO $ getModificationTime file return $ Map.insert mod (t,imps) menv _ -> return menv - return (k,MGrammar (sm:ss),menv2) --- reverse later + return (k,mGrammar (sm:modules gr),menv2) --- reverse later extendCompileEnv e@(k,_,_) file sm = extendCompileEnvInt e k (Just file) sm -- cgit v1.2.3