From 03430cce730a9b4e801f6fbfa7ec40e82f1315ff Mon Sep 17 00:00:00 2001 From: GeckoThePecko Date: Sat, 9 Mar 2024 01:48:13 -0500 Subject: [PATCH] perf(molangkit): use a map instead of a list in the flavorcache to not do a lookup every frame --- build.gradle | 2 +- .../eliotlash/molang/variables/ExecutionContext.java | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index cefbdad..d7a21df 100644 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/src/main/java/com/eliotlash/molang/variables/ExecutionContext.java b/src/main/java/com/eliotlash/molang/variables/ExecutionContext.java index a99faa7..47220a0 100644 --- a/src/main/java/com/eliotlash/molang/variables/ExecutionContext.java +++ b/src/main/java/com/eliotlash/molang/variables/ExecutionContext.java @@ -35,7 +35,7 @@ public class ExecutionContext { private final Evaluator evaluator; public final Stack contextStack = new Stack<>(); - public final Map>> flavorCache = new HashMap<>(); + public final Map> flavorCache = new HashMap<>(); public final Object2DoubleMap assignableMap = new Object2DoubleOpenHashMap<>(); public Object2DoubleMap functionScopedArguments = new Object2DoubleOpenHashMap<>(); @@ -84,13 +84,12 @@ public RuntimeVariable parseRuntimeVariable(String name, Expr.Access access) { } if (access != null) { - Pair pair = Pair.of(runtimeVariable, access); if (!flavorCache.containsKey(flavor)) { - flavorCache.put(flavor, new ArrayList<>()); + flavorCache.put(flavor, new HashMap<>()); } - List> list = flavorCache.get(flavor); - if (!list.contains(pair)) { - list.add(pair); + Map map = flavorCache.get(flavor); + if (!map.containsKey(runtimeVariable)) { + map.put(runtimeVariable, access); } } return runtimeVariable;