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

Unified Diff: src/wasm/encoder.cc

Issue 1781523002: [wasm] All strings are length-prefixed and inline (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: comment Created 4 years, 9 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/decoder.h ('k') | src/wasm/module-decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/encoder.cc
diff --git a/src/wasm/encoder.cc b/src/wasm/encoder.cc
index 91624782af8f85350e524dcb7e464a6937621991..4ed8e896b6252481db9f731268118deca0bfc995 100644
--- a/src/wasm/encoder.cc
+++ b/src/wasm/encoder.cc
@@ -180,7 +180,6 @@ void WasmFunctionBuilder::SetName(const unsigned char* name, int name_length) {
for (int i = 0; i < name_length; i++) {
name_.push_back(*(name + i));
}
- name_.push_back('\0');
}
}
@@ -287,7 +286,10 @@ WasmFunctionEncoder::WasmFunctionEncoder(Zone* zone, LocalType return_type,
uint32_t WasmFunctionEncoder::HeaderSize() const {
uint32_t size = 3;
if (!external_) size += 2;
- if (HasName()) size += 4;
+ if (HasName()) {
+ uint32_t name_size = NameSize();
+ size += static_cast<uint32_t>(SizeOfVarInt(name_size)) + name_size;
+ }
return size;
}
@@ -320,10 +322,10 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
EmitUint16(header, signature_index_);
if (HasName()) {
- uint32_t name_offset = static_cast<uint32_t>(*body - buffer);
- EmitUint32(header, name_offset);
- std::memcpy(*body, &name_[0], name_.size());
- (*body) += name_.size();
+ EmitVarInt(header, NameSize());
+ for (size_t i = 0; i < name_.size(); ++i) {
+ EmitUint8(header, name_[i]);
+ }
}
@@ -517,7 +519,8 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
sizes.AddSection(globals_.size());
if (globals_.size() > 0) {
- sizes.Add(kDeclGlobalSize * globals_.size(), 0);
+ /* These globals never have names, so are always 3 bytes. */
+ sizes.Add(3 * globals_.size(), 0);
}
sizes.AddSection(functions_.size());
@@ -564,7 +567,7 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
EmitVarInt(&header, globals_.size());
for (auto global : globals_) {
- EmitUint32(&header, 0);
+ EmitVarInt(&header, 0); // Length of the global name.
EmitUint8(&header, WasmOpcodes::MemTypeCodeFor(global.first));
EmitUint8(&header, global.second);
}
« no previous file with comments | « src/wasm/decoder.h ('k') | src/wasm/module-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698