From d40c6abd1799a72dc4eebfb474b9f5897b55d276 Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Tue, 9 May 2017 11:39:09 +0200 Subject: [PATCH] [asm.js] Cleanup vector use in WasmModuleBuilder. R=clemensh@chromium.org Change-Id: Ifa9f0f510bc5b864ebba199603919adb6a35d3a1 Reviewed-on: https://chromium-review.googlesource.com/500267 Reviewed-by: Clemens Hammacher Commit-Queue: Michael Starzinger Cr-Commit-Position: refs/heads/master@{#45190} --- src/asmjs/asm-parser.cc | 8 +++----- src/wasm/wasm-module-builder.cc | 8 ++++---- src/wasm/wasm-module-builder.h | 12 +++++------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/asmjs/asm-parser.cc b/src/asmjs/asm-parser.cc index acb6116665..131a7a70e6 100644 --- a/src/asmjs/asm-parser.cc +++ b/src/asmjs/asm-parser.cc @@ -365,8 +365,7 @@ void AsmJsParser::ValidateModule() { module_builder_->MarkStartFunction(start); for (auto& global_import : global_imports_) { uint32_t import_index = module_builder_->AddGlobalImport( - global_import.import_name.start(), global_import.import_name.length(), - global_import.value_type); + global_import.import_name, global_import.value_type); start->EmitWithI32V(kExprGetGlobal, import_index); start->EmitWithI32V(kExprSetGlobal, VarIndex(global_import.var_info)); } @@ -2150,9 +2149,8 @@ AsmType* AsmJsParser::ValidateCall() { if (it != function_info->import->cache.end()) { index = it->second; } else { - index = module_builder_->AddImport( - function_info->import->function_name.start(), - function_info->import->function_name.length(), sig); + index = + module_builder_->AddImport(function_info->import->function_name, sig); function_info->import->cache[sig] = index; } current_function_builder_->AddAsmWasmOffset(call_pos, to_number_pos); diff --git a/src/wasm/wasm-module-builder.cc b/src/wasm/wasm-module-builder.cc index cd6f5bbcee..adfea16764 100644 --- a/src/wasm/wasm-module-builder.cc +++ b/src/wasm/wasm-module-builder.cc @@ -308,16 +308,16 @@ void WasmModuleBuilder::SetIndirectFunction(uint32_t indirect, indirect_functions_[indirect] = direct; } -uint32_t WasmModuleBuilder::AddImport(const char* name, int name_length, +uint32_t WasmModuleBuilder::AddImport(Vector name, FunctionSig* sig) { - function_imports_.push_back({AddSignature(sig), name, name_length}); + function_imports_.push_back({AddSignature(sig), name.start(), name.length()}); return static_cast(function_imports_.size() - 1); } -uint32_t WasmModuleBuilder::AddGlobalImport(const char* name, int name_length, +uint32_t WasmModuleBuilder::AddGlobalImport(Vector name, ValueType type) { global_imports_.push_back( - {WasmOpcodes::ValueTypeCodeFor(type), name, name_length}); + {WasmOpcodes::ValueTypeCodeFor(type), name.start(), name.length()}); return static_cast(global_imports_.size() - 1); } diff --git a/src/wasm/wasm-module-builder.h b/src/wasm/wasm-module-builder.h index 6b2bbf1bcb..c6e6e55564 100644 --- a/src/wasm/wasm-module-builder.h +++ b/src/wasm/wasm-module-builder.h @@ -260,17 +260,15 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject { explicit WasmModuleBuilder(Zone* zone); // Building methods. - // TODO(mstarzinger): Refactor to take Vector instead. - uint32_t AddImport(const char* name, int name_length, FunctionSig* sig); - void SetImportName(uint32_t index, const char* name, int name_length) { - function_imports_[index].name = name; - function_imports_[index].name_length = name_length; + uint32_t AddImport(Vector name, FunctionSig* sig); + void SetImportName(uint32_t index, Vector name) { + function_imports_[index].name = name.start(); + function_imports_[index].name_length = name.length(); } WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr); uint32_t AddGlobal(ValueType type, bool exported, bool mutability = true, const WasmInitExpr& init = WasmInitExpr()); - // TODO(mstarzinger): Refactor to take Vector instead. - uint32_t AddGlobalImport(const char* name, int name_length, ValueType type); + uint32_t AddGlobalImport(Vector name, ValueType type); void AddDataSegment(const byte* data, uint32_t size, uint32_t dest); uint32_t AddSignature(FunctionSig* sig); uint32_t AllocateIndirectFunctions(uint32_t count);