diff --git a/src/heap/array-buffer-collector.cc b/src/heap/array-buffer-collector.cc index 63aa8db17e..bce22c39ba 100644 --- a/src/heap/array-buffer-collector.cc +++ b/src/heap/array-buffer-collector.cc @@ -12,18 +12,18 @@ namespace v8 { namespace internal { void ArrayBufferCollector::AddGarbageAllocations( - std::vector* allocations) { + std::vector allocations) { base::LockGuard guard(&allocations_mutex_); - allocations_.push_back(allocations); + allocations_.push_back(std::move(allocations)); } void ArrayBufferCollector::FreeAllocations() { base::LockGuard guard(&allocations_mutex_); - for (std::vector* allocations : allocations_) { - for (auto alloc : *allocations) { + for (const std::vector& allocations : + allocations_) { + for (JSArrayBuffer::Allocation alloc : allocations) { JSArrayBuffer::FreeBackingStore(heap_->isolate(), alloc); } - delete allocations; } allocations_.clear(); } diff --git a/src/heap/array-buffer-collector.h b/src/heap/array-buffer-collector.h index 002eba9a43..b44af2f2ad 100644 --- a/src/heap/array-buffer-collector.h +++ b/src/heap/array-buffer-collector.h @@ -28,7 +28,7 @@ class ArrayBufferCollector { // These allocations will begin to be freed once FreeAllocations() is called, // or on TearDown. void AddGarbageAllocations( - std::vector* allocations); + std::vector allocations); // Calls FreeAllocations() on a background thread. void FreeAllocationsOnBackgroundThread(); @@ -42,7 +42,7 @@ class ArrayBufferCollector { Heap* heap_; base::Mutex allocations_mutex_; - std::vector*> allocations_; + std::vector> allocations_; }; } // namespace internal diff --git a/src/heap/array-buffer-tracker.cc b/src/heap/array-buffer-tracker.cc index 96004a945e..b806248bd4 100644 --- a/src/heap/array-buffer-tracker.cc +++ b/src/heap/array-buffer-tracker.cc @@ -20,8 +20,7 @@ LocalArrayBufferTracker::~LocalArrayBufferTracker() { template void LocalArrayBufferTracker::Process(Callback callback) { - std::vector* backing_stores_to_free = - new std::vector(); + std::vector backing_stores_to_free; JSArrayBuffer* new_buffer = nullptr; JSArrayBuffer* old_buffer = nullptr; @@ -54,7 +53,7 @@ void LocalArrayBufferTracker::Process(Callback callback) { // We pass backing_store() and stored length to the collector for freeing // the backing store. Wasm allocations will go through their own tracker // based on the backing store. - backing_stores_to_free->emplace_back( + backing_stores_to_free.emplace_back( old_buffer->backing_store(), it->second, old_buffer->backing_store(), old_buffer->allocation_mode(), old_buffer->is_wasm_memory()); it = array_buffers_.erase(it); @@ -73,9 +72,8 @@ void LocalArrayBufferTracker::Process(Callback callback) { // Pass the backing stores that need to be freed to the main thread for later // distribution. - // ArrayBufferCollector takes ownership of this pointer. space_->heap()->array_buffer_collector()->AddGarbageAllocations( - backing_stores_to_free); + std::move(backing_stores_to_free)); } void ArrayBufferTracker::PrepareToFreeDeadInNewSpace(Heap* heap) {