Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Unified Diff: src/wasm/wasm-module-builder.cc

Issue 2406133003: [wasm] Decouple function name and exported name in WasmFunctionBuilder (Closed)
Patch Set: Change interface to Vector<const char>; avoids size_t/int confusion Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module-builder.cc
diff --git a/src/wasm/wasm-module-builder.cc b/src/wasm/wasm-module-builder.cc
index 941a0736c3272a53488121a3e3309619e4d90646..3efcb090aa62796aafb82473775f4a4aa4e08b74 100644
--- a/src/wasm/wasm-module-builder.cc
+++ b/src/wasm/wasm-module-builder.cc
@@ -54,6 +54,7 @@ WasmFunctionBuilder::WasmFunctionBuilder(WasmModuleBuilder* builder)
func_index_(static_cast<uint32_t>(builder->functions_.size())),
body_(builder->zone()),
name_(builder->zone()),
+ exported_name_(builder->zone()),
i32_temps_(builder->zone()),
i64_temps_(builder->zone()),
f32_temps_(builder->zone()),
@@ -139,15 +140,17 @@ void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) {
EmitCode(code, sizeof(code));
}
-void WasmFunctionBuilder::SetExported() { exported_ = true; }
+void WasmFunctionBuilder::Export() { exported_ = true; }
-void WasmFunctionBuilder::SetName(const char* name, int name_length) {
- name_.clear();
- if (name_length > 0) {
- for (int i = 0; i < name_length; ++i) {
- name_.push_back(*(name + i));
- }
- }
+void WasmFunctionBuilder::ExportAs(Vector<const char> name) {
+ exported_ = true;
+ exported_name_.resize(name.length());
+ memcpy(exported_name_.data(), name.start(), name.length());
+}
+
+void WasmFunctionBuilder::SetName(Vector<const char> name) {
+ name_.resize(name.length());
+ memcpy(name_.data(), name.start(), name.length());
}
void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const {
@@ -156,10 +159,11 @@ void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const {
void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer) const {
if (exported_) {
- buffer.write_size(name_.size());
- if (name_.size() > 0) {
- buffer.write(reinterpret_cast<const byte*>(&name_[0]), name_.size());
- }
+ const ZoneVector<char>* exported_name =
+ exported_name_.size() == 0 ? &name_ : &exported_name_;
+ buffer.write_size(exported_name->size());
+ buffer.write(reinterpret_cast<const byte*>(exported_name->data()),
+ exported_name->size());
buffer.write_u8(kExternalFunction);
buffer.write_u32v(func_index_ +
static_cast<uint32_t>(builder_->imports_.size()));
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698