LibWasm: Remove Module::functions

`Module::functions` created clones of all of the functions in the
module. It provided a _slightly_ better API, but ended up costing around
40ms when instantiating spidermonkey.
This commit is contained in:
Diego Frias
2024-07-27 16:44:36 -07:00
committed by Ali Mohammad Pur
parent 2d95cc01dc
commit dc52998341
8 changed files with 36 additions and 111 deletions

View File

@@ -1403,42 +1403,6 @@ ParseResult<Module> Module::parse(Stream& stream)
return Module { move(sections) };
}
bool Module::populate_sections()
{
auto is_ok = true;
FunctionSection const* function_section { nullptr };
bool seen_code_section = false;
for_each_section_of_type<FunctionSection>([&](FunctionSection const& section) { function_section = &section; });
for_each_section_of_type<CodeSection>([&](CodeSection const& section) {
if (!function_section && section.functions().is_empty()) {
return;
}
if (!function_section || function_section->types().size() != section.functions().size()) {
is_ok = false;
return;
}
seen_code_section = true;
size_t index = 0;
for (auto& entry : section.functions()) {
if (function_section->types().size() <= index) {
is_ok = false;
return;
}
auto& type_index = function_section->types()[index];
Vector<ValueType> locals;
for (auto& local : entry.func().locals()) {
for (size_t i = 0; i < local.n(); ++i)
locals.append(local.type());
}
m_functions.empend(type_index, move(locals), entry.func().body());
++index;
}
});
if (!seen_code_section && function_section && !function_section->types().is_empty())
return false;
return is_ok;
}
ByteString parse_error_to_byte_string(ParseError error)
{
switch (error) {