Skip to content

Commit 34906bf

Browse files
authored
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).
1 parent f0a5e48 commit 34906bf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/wasm/wasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ void Function::clearDebugInfo() {
15231523

15241524
template<typename Map>
15251525
typename Map::mapped_type&
1526-
getModuleElement(Map& m, Name name, const std::string& funcName) {
1526+
getModuleElement(Map& m, Name name, std::string_view funcName) {
15271527
auto iter = m.find(name);
15281528
if (iter == m.end()) {
15291529
Fatal() << "Module::" << funcName << ": " << name << " does not exist";

0 commit comments

Comments
 (0)