Skip to content

Commit 03430cc

Browse files
committed
perf(molangkit): use a map instead of a list in the flavorcache to not do a lookup every frame
1 parent bb7e919 commit 03430cc

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414

1515
apply plugin: 'maven-publish'
1616
apply plugin: 'com.google.cloud.artifactregistry.gradle-plugin'
17-
version = "1.0.10"
17+
version = "1.0.11"
1818
group = "com.eliotlash.molang"
1919
archivesBaseName = "particleman"
2020

src/main/java/com/eliotlash/molang/variables/ExecutionContext.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ExecutionContext {
3535
private final Evaluator evaluator;
3636

3737
public final Stack<Expr.Access> contextStack = new Stack<>();
38-
public final Map<VariableFlavor, List<Pair<RuntimeVariable, Expr.Access>>> flavorCache = new HashMap<>();
38+
public final Map<VariableFlavor, Map<RuntimeVariable, Expr.Access>> flavorCache = new HashMap<>();
3939
public final Object2DoubleMap<Assignable> assignableMap = new Object2DoubleOpenHashMap<>();
4040
public Object2DoubleMap<Assignable> functionScopedArguments = new Object2DoubleOpenHashMap<>();
4141

@@ -84,13 +84,12 @@ public RuntimeVariable parseRuntimeVariable(String name, Expr.Access access) {
8484
}
8585

8686
if (access != null) {
87-
Pair<RuntimeVariable, Expr.Access> pair = Pair.of(runtimeVariable, access);
8887
if (!flavorCache.containsKey(flavor)) {
89-
flavorCache.put(flavor, new ArrayList<>());
88+
flavorCache.put(flavor, new HashMap<>());
9089
}
91-
List<Pair<RuntimeVariable, Expr.Access>> list = flavorCache.get(flavor);
92-
if (!list.contains(pair)) {
93-
list.add(pair);
90+
Map<RuntimeVariable, Expr.Access> map = flavorCache.get(flavor);
91+
if (!map.containsKey(runtimeVariable)) {
92+
map.put(runtimeVariable, access);
9493
}
9594
}
9695
return runtimeVariable;

0 commit comments

Comments
 (0)