Skip to content

Commit

Permalink
perf(molangkit): use a map instead of a list in the flavorcache to no…
Browse files Browse the repository at this point in the history
…t do a lookup every frame
  • Loading branch information
bernie-g committed Mar 9, 2024
1 parent bb7e919 commit 03430cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {

apply plugin: 'maven-publish'
apply plugin: 'com.google.cloud.artifactregistry.gradle-plugin'
version = "1.0.10"
version = "1.0.11"
group = "com.eliotlash.molang"
archivesBaseName = "particleman"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ExecutionContext {
private final Evaluator evaluator;

public final Stack<Expr.Access> contextStack = new Stack<>();
public final Map<VariableFlavor, List<Pair<RuntimeVariable, Expr.Access>>> flavorCache = new HashMap<>();
public final Map<VariableFlavor, Map<RuntimeVariable, Expr.Access>> flavorCache = new HashMap<>();
public final Object2DoubleMap<Assignable> assignableMap = new Object2DoubleOpenHashMap<>();
public Object2DoubleMap<Assignable> functionScopedArguments = new Object2DoubleOpenHashMap<>();

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

if (access != null) {
Pair<RuntimeVariable, Expr.Access> pair = Pair.of(runtimeVariable, access);
if (!flavorCache.containsKey(flavor)) {
flavorCache.put(flavor, new ArrayList<>());
flavorCache.put(flavor, new HashMap<>());
}
List<Pair<RuntimeVariable, Expr.Access>> list = flavorCache.get(flavor);
if (!list.contains(pair)) {
list.add(pair);
Map<RuntimeVariable, Expr.Access> map = flavorCache.get(flavor);
if (!map.containsKey(runtimeVariable)) {
map.put(runtimeVariable, access);
}
}
return runtimeVariable;
Expand Down

0 comments on commit 03430cc

Please sign in to comment.