Skip to content

Commit b3c4a07

Browse files
committed
one cached map for each input map
1 parent a0cfe10 commit b3c4a07

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public abstract class MapRequest extends UserRequest<Object> {
6969

7070
private static Long lastMapModified = 0L;
7171
private static String lastMapPath = "";
72-
protected String cachedMapFileName = "cached_map.w3x";
72+
protected String cachedMapFileName = "";
7373

7474
public static final String BUILD_CONFIGURED_SCRIPT_NAME = "01_war3mapj_with_config.j.txt";
7575
public static final String BUILD_COMPILED_JASS_NAME = "02_compiled.j.txt";
@@ -411,7 +411,24 @@ protected File getCachedMapFile() {
411411
if (!cacheDir.exists()) {
412412
UtilsIO.mkdirs(cacheDir);
413413
}
414-
return new File(cacheDir, cachedMapFileName);
414+
return new File(cacheDir, resolveCachedMapFileName());
415+
}
416+
417+
private String resolveCachedMapFileName() {
418+
if (!cachedMapFileName.isEmpty()) {
419+
return cachedMapFileName;
420+
}
421+
if (!map.isPresent()) {
422+
return "cached_map.w3x";
423+
}
424+
File inputMap = map.get();
425+
String inputName = inputMap.getName();
426+
int dot = inputName.lastIndexOf('.');
427+
String baseName = dot > 0 ? inputName.substring(0, dot) : inputName;
428+
// Keep only filesystem-safe characters and avoid collisions for same basename from different folders.
429+
String safeBase = baseName.replaceAll("[^a-zA-Z0-9._-]", "_");
430+
String pathHash = Integer.toUnsignedString(inputMap.getAbsolutePath().hashCode(), 36);
431+
return safeBase + "_" + pathHash + "_cached.w3x";
415432
}
416433

417434
protected File ensureWritableTargetFile(File targetFile, String dialogTitle, String lockMessage,

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/CyclicFunctionRemover.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ private void removeCycles(List<List<ImFunction>> components) {
4141
for (List<ImFunction> component : components) {
4242
if (component.size() > 1) {
4343
// keep list for order; set for O(1) membership
44-
Set<ImFunction> funcSet = new HashSet<>(component);
44+
Set<ImFunction> funcSet = Collections.newSetFromMap(new IdentityHashMap<>());
45+
funcSet.addAll(component);
4546
removeCycle(component, funcSet);
4647
}
4748
}
4849
}
4950

5051
private void removeCycle(List<ImFunction> funcs, Set<ImFunction> funcSet) {
5152
List<ImVar> newParameters = Lists.newArrayList();
52-
Map<ImVar, ImVar> oldToNewVar = Maps.newLinkedHashMap();
53+
Map<ImVar, ImVar> oldToNewVar = new IdentityHashMap<>();
5354

5455
calculateNewParameters(funcs, newParameters, oldToNewVar);
5556

@@ -90,11 +91,11 @@ private void removeCycle(List<ImFunction> funcs, Set<ImFunction> funcSet) {
9091
stmts = elseBlock;
9192
}
9293

93-
Map<ImFunction, Integer> funcToIndex = new HashMap<>();
94+
Map<ImFunction, Integer> funcToIndex = new IdentityHashMap<>();
9495
for (int i = 0; i < funcs.size(); i++) {
9596
funcToIndex.put(funcs.get(i), i);
9697
}
97-
Map<ImFunction, ImFunction> proxyByOriginal = new HashMap<>();
98+
Map<ImFunction, ImFunction> proxyByOriginal = new IdentityHashMap<>();
9899
// Rewrite only affected roots:
99100
// - merged cycle body (contains moved bodies from all old funcs)
100101
// - callers that directly call any removed function
@@ -107,8 +108,8 @@ private void removeCycle(List<ImFunction> funcs, Set<ImFunction> funcSet) {
107108
}
108109
for (ImFunction caller : new ArrayList<>(tr.getCalledFunctions().keySet())) {
109110
Collection<ImFunction> called = tr.getCalledFunctions().get(caller);
110-
for (ImFunction removed : funcSet) {
111-
if (called.contains(removed)) {
111+
for (ImFunction c : called) {
112+
if (funcSet.contains(c)) {
112113
rewriteRoots.add(caller.getBody());
113114
break;
114115
}

0 commit comments

Comments
 (0)