Skip to content

Commit 47d9137

Browse files
committed
Avoid one binary content copying
Reuse `bytecode` instead of creating and copy the binary content during `wasm_byte_vec_new()` Signed-off-by: [email protected] <[email protected]>
1 parent 609960c commit 47d9137

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/wamr/wamr.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ bool Wamr::load(std::string_view bytecode, std::string_view /*precompiled*/,
125125
return false;
126126
}
127127

128-
WasmByteVec vec;
129-
wasm_byte_vec_new(vec.get(), bytecode.size(), bytecode.data());
130-
131-
module_ = wasm_module_new(store_.get(), vec.get());
128+
wasm_byte_vec_t binary = {.size = bytecode.size(),
129+
.data = (char *)bytecode.data(),
130+
.num_elems = bytecode.size(),
131+
.size_of_elem = sizeof(byte_t),
132+
.lock = nullptr};
133+
module_ = wasm_module_new(store_.get(), &binary);
132134
if (module_ == nullptr) {
133135
return false;
134136
}
@@ -344,11 +346,10 @@ bool Wamr::link(std::string_view /*debug_name*/) {
344346
wasm_instance_exports(instance_.get(), exports.get());
345347

346348
for (size_t i = 0; i < export_types.get()->size; i++) {
347-
const wasm_externtype_t *exp_extern_type = wasm_exporttype_type(export_types.get()->data[i]);
348349
wasm_extern_t *actual_extern = exports.get()->data[i];
349350

350351
wasm_externkind_t kind = wasm_extern_kind(actual_extern);
351-
assert(kind == wasm_externtype_kind(exp_extern_type));
352+
assert(kind == wasm_externtype_kind(wasm_exporttype_type(export_types.get()->data[i])));
352353
switch (kind) {
353354
case WASM_EXTERN_FUNC: {
354355
WasmFuncPtr func = wasm_func_copy(wasm_extern_as_func(actual_extern));

0 commit comments

Comments
 (0)