diff options
author | Petr Makhnev <51853996+i582@users.noreply.github.com> | 2024-10-11 03:15:28 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-10 16:15:28 -0700 |
commit | 34906bfbc99d31b3e62d2d006af2247d8418ba2f (patch) | |
tree | dd0408aef3abbbdcc13064cec8c5e6d4780013d4 /src/wasm/wasm.cpp | |
parent | f0a5e488ae68074837706edafb54050e56cf9937 (diff) | |
download | binaryen-34906bfbc99d31b3e62d2d006af2247d8418ba2f.tar.gz binaryen-34906bfbc99d31b3e62d2d006af2247d8418ba2f.tar.bz2 binaryen-34906bfbc99d31b3e62d2d006af2247d8418ba2f.zip |
Optimize Module::get_* family of functions with std::string_view in getModuleElement (#6998)
Passing a constant string to functions requires memory allocation, and
allocation is inherently slow. Since we are using C++17, we can use
string_view and remove this unnecessary allocation.
Although the code seems simple enough for the optimizer to remove this
allocation after inlining, tests on Clang 18 show that this is not the
case (on Apple Silicon at least).
Diffstat (limited to 'src/wasm/wasm.cpp')
-rw-r--r-- | src/wasm/wasm.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index e8de4572b..0245fc01e 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -1523,7 +1523,7 @@ void Function::clearDebugInfo() { template<typename Map> typename Map::mapped_type& -getModuleElement(Map& m, Name name, const std::string& funcName) { +getModuleElement(Map& m, Name name, std::string_view funcName) { auto iter = m.find(name); if (iter == m.end()) { Fatal() << "Module::" << funcName << ": " << name << " does not exist"; |