@@ -78,10 +78,11 @@ public class ModuleEnvironment extends Environment {
78
78
private boolean bootstrap ;
79
79
private String deprecated ;
80
80
protected Map <String , AbstractFunction > resourceImporters ;
81
+ protected Map <Type , Set <GenericKeywordParameters >> cachedGeneralKeywordParameters ;
81
82
82
83
protected static final TypeFactory TF = TypeFactory .getInstance ();
83
84
84
- public final static String SHELL_MODULE = "$shell$ " ;
85
+ public final static String SHELL_MODULE = "$" ;
85
86
86
87
public ModuleEnvironment (String name , GlobalEnvironment heap ) {
87
88
super (ValueFactoryFactory .getValueFactory ().sourceLocation (URIUtil .assumeCorrect ("main" , name , "" )), name );
@@ -95,6 +96,7 @@ public ModuleEnvironment(String name, GlobalEnvironment heap) {
95
96
this .syntaxDefined = false ;
96
97
this .bootstrap = false ;
97
98
this .resourceImporters = new HashMap <String , AbstractFunction >();
99
+ this .cachedGeneralKeywordParameters = null ;
98
100
}
99
101
100
102
/**
@@ -113,25 +115,27 @@ protected ModuleEnvironment(ModuleEnvironment env) {
113
115
this .syntaxDefined = env .syntaxDefined ;
114
116
this .bootstrap = env .bootstrap ;
115
117
this .resourceImporters = env .resourceImporters ;
118
+ this .cachedGeneralKeywordParameters = null ;
116
119
this .deprecated = env .deprecated ;
117
120
}
118
121
119
122
@ Override
120
123
public void reset () {
121
124
super .reset ();
122
- this .importedModules = new HashSet <String >();
123
- this .concreteSyntaxTypes = new HashMap <String , NonTerminalType >();
125
+ this .importedModules = new HashSet <>();
126
+ this .concreteSyntaxTypes = new HashMap <>();
124
127
this .typeStore = new TypeStore ();
125
128
this .productions = new HashSet <IValue >();
126
129
this .initialized = false ;
127
130
this .syntaxDefined = false ;
128
131
this .bootstrap = false ;
129
132
this .extended = new HashSet <String >();
130
133
this .deprecated = null ;
134
+ this .generalKeywordParameters = new HashMap <>();
135
+ this .cachedGeneralKeywordParameters = null ;
131
136
}
132
137
133
138
public void extend (ModuleEnvironment other ) {
134
- // super.extend(other);
135
139
extendNameFlags (other );
136
140
137
141
// First extend the imports before functions and variables
@@ -386,10 +390,12 @@ public void unImport(String moduleName) {
386
390
typeStore .unimportStores (new TypeStore [] { old .getStore () });
387
391
}
388
392
}
393
+ cachedGeneralKeywordParameters = null ;
389
394
}
390
395
391
396
public void unExtend (String moduleName ) {
392
397
extended .remove (moduleName );
398
+ cachedGeneralKeywordParameters = null ;
393
399
}
394
400
395
401
@ Override
@@ -710,6 +716,16 @@ public List<KeywordFormal> getFormals() {
710
716
711
717
@ Override
712
718
public Set <GenericKeywordParameters > lookupGenericKeywordParameters (Type adt ) {
719
+ if (cachedGeneralKeywordParameters != null ) {
720
+ var result = cachedGeneralKeywordParameters .get (adt );
721
+ if (result != null ) {
722
+ return result ;
723
+ }
724
+ }
725
+ else {
726
+ cachedGeneralKeywordParameters = io .usethesource .capsule .Map .Transient .of ();
727
+ }
728
+
713
729
Set <GenericKeywordParameters > result = new HashSet <>();
714
730
List <KeywordFormal > list = generalKeywordParameters .get (adt );
715
731
if (list != null ) {
@@ -725,6 +741,9 @@ public Set<GenericKeywordParameters> lookupGenericKeywordParameters(Type adt) {
725
741
}
726
742
}
727
743
744
+ // save the result for next time
745
+ cachedGeneralKeywordParameters .put (adt , result );
746
+
728
747
return result ;
729
748
}
730
749
0 commit comments