From a191d66fce93829e7365f7f2f4be2799c62a1ee4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 30 Nov 2023 11:52:57 -0800 Subject: wasm-metadce: Improve name deduplication (#6138) Avoid adding suffixes when we don't need them to keep names unique. As background, the suffixes are not used by emcc at all, so they are just for internal use in the tool. How that works is that metadce gets as input the list of things the user cares about, with names for them, so it knows the proper names to give imports and exports, and makes up names for other things. Those made up names will not be read by the user, so we can make them prettier as this PR does without breaking anything. The main benefit of this PR is to make debugging easier. --- src/tools/wasm-metadce.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/tools/wasm-metadce.cpp b/src/tools/wasm-metadce.cpp index d81054d32..73d7c0691 100644 --- a/src/tools/wasm-metadce.cpp +++ b/src/tools/wasm-metadce.cpp @@ -307,9 +307,12 @@ struct MetaDCEGraph { private: // gets a unique name for the graph Name getName(std::string prefix1, std::string prefix2) { + auto base = prefix1 + '$' + prefix2; + if (nodes.find(base) == nodes.end()) { + return base; + } while (1) { - auto curr = - Name(prefix1 + '$' + prefix2 + '$' + std::to_string(nameIndex++)); + Name curr = base + '$' + std::to_string(nameIndex++); if (nodes.find(curr) == nodes.end()) { return curr; } -- cgit v1.2.3