From b83450ed1fd98cec4453024f57f892b31851ea50 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Tue, 11 Oct 2022 11:16:14 -0500 Subject: Make `Name` a pointer, length pair (#5122) With the goal of supporting null characters (i.e. zero bytes) in strings. Rewrite the underlying interned `IString` to store a `std::string_view` rather than a `const char*`, reduce the number of map lookups necessary to intern a string, and present a more immutable interface. Most importantly, replace the `c_str()` method that returned a `const char*` with a `toString()` method that returns a `std::string`. This new method can correctly handle strings containing null characters. A `const char*` can still be had by calling `data()` on the `std::string_view`, although this usage should be discouraged. This change is NFC in spirit, although not in practice. It does not intend to support any particular new functionality, but it is probably now possible to use strings containing null characters in at least some cases. At least one parser bug is also incidentally fixed. Follow-on PRs will explicitly support and test strings containing nulls for particular use cases. The C API still uses `const char*` to represent strings. As strings containing nulls become better supported by the rest of Binaryen, this will no longer be sufficient. Updating the C and JS APIs to use pointer, length pairs is left as future work. --- src/passes/MergeSimilarFunctions.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/passes/MergeSimilarFunctions.cpp') diff --git a/src/passes/MergeSimilarFunctions.cpp b/src/passes/MergeSimilarFunctions.cpp index e5e50423a..8e039566a 100644 --- a/src/passes/MergeSimilarFunctions.cpp +++ b/src/passes/MergeSimilarFunctions.cpp @@ -526,8 +526,9 @@ bool EquivalentClass::hasMergeBenefit(Module* module, Function* EquivalentClass::createShared(Module* module, const std::vector& params) { - Name fnName = Names::getValidFunctionName( - *module, std::string("byn$mgfn-shared$") + primaryFunction->name.str); + Name fnName = Names::getValidFunctionName(*module, + std::string("byn$mgfn-shared$") + + primaryFunction->name.toString()); Builder builder(*module); std::vector sigParams; Index extraParamBase = primaryFunction->getNumParams(); -- cgit v1.2.3