From 31f91bc63c58229f518629ed0306ccf8616f133c Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 16 May 2022 11:59:25 +0300 Subject: [PATCH] C: fix overlapping file names --- .../generate/ShorteningFileNameProvider.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/c/generate/ShorteningFileNameProvider.java b/core/src/main/java/org/teavm/backend/c/generate/ShorteningFileNameProvider.java index 95a44b10f..ef6ca9867 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/ShorteningFileNameProvider.java +++ b/core/src/main/java/org/teavm/backend/c/generate/ShorteningFileNameProvider.java @@ -32,32 +32,34 @@ public class ShorteningFileNameProvider implements FileNameProvider { @Override public String fileName(String className) { - return unique(shorten(nameProvider.fileName(className))); + return process(nameProvider.fileName(className)); } @Override public String fileName(ValueType type) { - return unique(shorten(nameProvider.fileName(type))); + return process(nameProvider.fileName(type)); } @Override public String escapeName(String name) { - return unique(shorten(nameProvider.escapeName(name))); + return process(nameProvider.escapeName(name)); + } + + private String process(String name) { + return names.computeIfAbsent(name, n -> unique(shorten(n))); } private String unique(String name) { - return names.computeIfAbsent(name, n -> { - if (usedNames.add(n)) { - return n; + if (usedNames.add(name)) { + return name; + } + int suffix = 1; + while (true) { + String candidate = name + "_" + suffix++; + if (usedNames.add(candidate)) { + return candidate; } - int suffix = 1; - while (true) { - String candidate = n + "_" + suffix++; - if (usedNames.add(candidate)) { - return candidate; - } - } - }); + } } private static String shorten(String name) {