Commit 11f7e438 authored by Dan Elphick's avatar Dan Elphick Committed by V8 LUCI CQ

[utils] Use new instead of NewArray in Vector

Replace all uses of NewArray/DeleteArray with new[]/delete[] in
utils/vector.h which allows removing the dependency on
utils/allocation.h.

As a result allocation failures here will not call
FatalProcessOutOfMemory any more, but it's likely it wouldn't have been
called anyway.

Also adds some missing includes that were being previously being brought
in via vector.h depending on allocation.h.

Bug: v8:11879
Change-Id: I5055b49fad0d06642a9bd3eebb93a6a0e4acca60
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2968405Reviewed-by: 's avatarSimon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Auto-Submit: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75216}
parent 37ecee6a
......@@ -5,6 +5,7 @@
#include "src/inspector/v8-heap-profiler-agent-impl.h"
#include "include/v8-inspector.h"
#include "include/v8-platform.h"
#include "include/v8-profiler.h"
#include "include/v8-version.h"
#include "src/base/platform/mutex.h"
......
......@@ -5,6 +5,7 @@
#ifndef V8_SNAPSHOT_SNAPSHOT_UTILS_H_
#define V8_SNAPSHOT_SNAPSHOT_UTILS_H_
#include "src/common/globals.h"
#include "src/utils/vector.h"
namespace v8 {
......
......@@ -8,12 +8,12 @@
#include <algorithm>
#include <cstring>
#include <iterator>
#include <limits>
#include <memory>
#include <type_traits>
#include "src/common/checks.h"
#include "src/common/globals.h"
#include "src/utils/allocation.h"
#include "src/base/logging.h"
#include "src/base/macros.h"
namespace v8 {
namespace internal {
......@@ -32,7 +32,7 @@ class Vector {
}
static Vector<T> New(size_t length) {
return Vector<T>(NewArray<T>(length), length);
return Vector<T>(new T[length], length);
}
// Returns a vector using the same backing storage as this one,
......@@ -82,7 +82,7 @@ class Vector {
// Returns a clone of this vector with a new backing store.
Vector<T> Clone() const {
T* result = NewArray<T>(length_);
T* result = new T[length_];
for (size_t i = 0; i < length_; i++) result[i] = start_[i];
return Vector<T>(result, length_);
}
......@@ -95,7 +95,7 @@ class Vector {
// Releases the array underlying this vector. Once disposed the
// vector is empty.
void Dispose() {
DeleteArray(start_);
delete[] start_;
start_ = nullptr;
length_ = 0;
}
......@@ -143,9 +143,8 @@ class Vector {
template <typename T>
class V8_NODISCARD ScopedVector : public Vector<T> {
public:
explicit ScopedVector(size_t length)
: Vector<T>(NewArray<T>(length), length) {}
~ScopedVector() { DeleteArray(this->begin()); }
explicit ScopedVector(size_t length) : Vector<T>(new T[length], length) {}
~ScopedVector() { delete[] this->begin(); }
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedVector);
......
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