Commit 14f470ca authored by clemensh's avatar clemensh Committed by Commit bot

Enable emplace_back for zone containers

As required by C++11, this CL changes the zone allocator to be able to
construct and destroy arbitrary types, and accept arbitrary arguments
for construct, passing them via perfect forwarding.
I also change some push_back to emplace_back. Some of those did not
compile before.

R=ishell@chromium.org, titzer@chromium.org

Review-Url: https://codereview.chromium.org/2646873004
Cr-Commit-Position: refs/heads/master@{#42597}
parent 1f069202
......@@ -1201,7 +1201,7 @@ FunctionOffsetsResult DecodeWasmFunctionOffsets(const byte* module_start,
for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) {
uint32_t size = decoder.consume_u32v("body size");
int offset = static_cast<int>(section_offset + decoder.pc_offset());
table.push_back(std::make_pair(offset, static_cast<int>(size)));
table.emplace_back(offset, static_cast<int>(size));
DCHECK(table.back().first >= 0 && table.back().second >= 0);
decoder.consume_bytes(size);
}
......@@ -1224,7 +1224,7 @@ AsmJsOffsetsResult DecodeAsmJsOffsets(const byte* tables_start,
for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) {
uint32_t size = decoder.consume_u32v("table size");
if (size == 0) {
table.push_back(std::vector<AsmJsOffsetEntry>());
table.emplace_back();
continue;
}
if (!decoder.checkAvailable(size)) {
......
......@@ -1789,7 +1789,7 @@ class WasmInterpreterInternals : public ZoneObject {
codemap_(env.instance ? env.instance->module : nullptr,
module_bytes_.data(), zone),
threads_(zone) {
threads_.push_back(ThreadImpl(zone, &codemap_, env.instance));
threads_.emplace_back(zone, &codemap_, env.instance);
}
void Delete() { threads_.clear(); }
......
......@@ -90,8 +90,7 @@ void wasm::PrintWasmText(const WasmModule *module,
const int kMaxIndentation = 64;
int indentation = std::min(kMaxIndentation, 2 * control_depth);
if (offset_table) {
offset_table->push_back(debug::WasmDisassemblyOffsetTableEntry(
i.pc_offset(), line_nr, indentation));
offset_table->emplace_back(i.pc_offset(), line_nr, indentation);
}
// 64 whitespaces
......
......@@ -49,10 +49,15 @@ class zone_allocator {
size_type max_size() const throw() {
return std::numeric_limits<int>::max() / sizeof(value_type);
}
void construct(pointer p, const T& val) {
new (static_cast<void*>(p)) T(val);
template <typename U, typename... Args>
void construct(U* p, Args&&... args) {
void* v_p = const_cast<void*>(static_cast<const void*>(p));
new (v_p) U(std::forward<Args>(args)...);
}
template <typename U>
void destroy(U* p) {
p->~U();
}
void destroy(pointer p) { p->~T(); }
bool operator==(zone_allocator const& other) const {
return zone_ == other.zone_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment