Commit d29ef432 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Replace ZoneList with ZoneVector in frames, json-parser and

more.

Bug: v8:6333, v8:6921
Change-Id: I442190988f2c853560b28efa54e04ff73f9d94ca
Reviewed-on: https://chromium-review.googlesource.com/718343
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49111}
parent e4a97a2e
......@@ -17,6 +17,7 @@
#include "src/visitors.h"
#include "src/vm-state-inl.h"
#include "src/wasm/wasm-objects-inl.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
......@@ -2119,12 +2120,12 @@ static StackFrame* AllocateFrameCopy(StackFrame* frame, Zone* zone) {
Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone) {
ZoneList<StackFrame*> list(10, zone);
ZoneVector<StackFrame*> frames(zone);
for (StackFrameIterator it(isolate); !it.done(); it.Advance()) {
StackFrame* frame = AllocateFrameCopy(it.frame(), zone);
list.Add(frame, zone);
frames.push_back(frame);
}
return list.ToVector();
return Vector<StackFrame*>(frames.data(), frames.size());
}
......
......@@ -15,6 +15,7 @@
#include "src/string-hasher.h"
#include "src/transitions.h"
#include "src/unicode-cache.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
......@@ -332,7 +333,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonObject() {
factory()->NewJSObject(object_constructor(), pretenure_);
Handle<Map> map(json_object->map());
int descriptor = 0;
ZoneList<Handle<Object> > properties(8, zone());
ZoneVector<Handle<Object>> properties(zone());
DCHECK_EQ(c0_, '{');
bool transitioning = true;
......@@ -411,7 +412,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonObject() {
DCHECK(target->instance_descriptors()
->GetFieldType(descriptor)
->NowContains(value));
properties.Add(value, zone());
properties.push_back(value);
map = target;
descriptor++;
continue;
......@@ -479,13 +480,13 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonObject() {
template <bool seq_one_byte>
void JsonParser<seq_one_byte>::CommitStateToJsonObject(
Handle<JSObject> json_object, Handle<Map> map,
ZoneList<Handle<Object> >* properties) {
ZoneVector<Handle<Object>>* properties) {
JSObject::AllocateStorageForMap(json_object, map);
DCHECK(!json_object->map()->is_dictionary_map());
DisallowHeapAllocation no_gc;
DescriptorArray* descriptors = json_object->map()->instance_descriptors();
int length = properties->length();
int length = static_cast<int>(properties->size());
for (int i = 0; i < length; i++) {
Handle<Object> value = (*properties)[i];
// Initializing store.
......@@ -537,7 +538,7 @@ class ElementKindLattice {
template <bool seq_one_byte>
Handle<Object> JsonParser<seq_one_byte>::ParseJsonArray() {
HandleScope scope(isolate());
ZoneList<Handle<Object> > elements(4, zone());
ZoneVector<Handle<Object>> elements(zone());
DCHECK_EQ(c0_, '[');
ElementKindLattice lattice;
......@@ -547,7 +548,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonArray() {
do {
Handle<Object> element = ParseJsonValue();
if (element.is_null()) return ReportUnexpectedCharacter();
elements.Add(element, zone());
elements.push_back(element);
lattice.Update(element);
} while (MatchSkipWhiteSpace(','));
if (c0_ != ']') {
......@@ -560,20 +561,21 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonArray() {
Handle<Object> json_array;
const ElementsKind kind = lattice.GetElementsKind();
int elements_size = static_cast<int>(elements.size());
switch (kind) {
case PACKED_ELEMENTS:
case PACKED_SMI_ELEMENTS: {
Handle<FixedArray> elems =
factory()->NewFixedArray(elements.length(), pretenure_);
for (int i = 0; i < elements.length(); i++) elems->set(i, *elements[i]);
factory()->NewFixedArray(elements_size, pretenure_);
for (int i = 0; i < elements_size; i++) elems->set(i, *elements[i]);
json_array = factory()->NewJSArrayWithElements(elems, kind, pretenure_);
break;
}
case PACKED_DOUBLE_ELEMENTS: {
Handle<FixedDoubleArray> elems = Handle<FixedDoubleArray>::cast(
factory()->NewFixedDoubleArray(elements.length(), pretenure_));
for (int i = 0; i < elements.length(); i++) {
factory()->NewFixedDoubleArray(elements_size, pretenure_));
for (int i = 0; i < elements_size; i++) {
elems->set(i, elements[i]->Number());
}
json_array = factory()->NewJSArrayWithElements(elems, kind, pretenure_);
......
......@@ -144,7 +144,7 @@ class JsonParser BASE_EMBEDDED {
Zone* zone() { return &zone_; }
void CommitStateToJsonObject(Handle<JSObject> json_object, Handle<Map> map,
ZoneList<Handle<Object> >* properties);
ZoneVector<Handle<Object>>* properties);
Handle<String> source_;
int source_length_;
......
......@@ -6,6 +6,7 @@
#define V8_ZONE_ZONE_HANDLE_SET_H_
#include "src/handles.h"
#include "src/zone/zone-containers.h"
#include "src/zone/zone.h"
namespace v8 {
......@@ -25,7 +26,7 @@ class ZoneHandleSet final {
size_t size() const {
if ((data_ & kTagMask) == kEmptyTag) return 0;
if ((data_ & kTagMask) == kSingletonTag) return 1;
return list()->length();
return list()->size();
}
Handle<T> at(size_t i) const {
......@@ -46,34 +47,35 @@ class ZoneHandleSet final {
data_ = bit_cast<intptr_t>(value) | kSingletonTag;
} else if ((data_ & kTagMask) == kSingletonTag) {
if (singleton() == value) return;
List* list = new (zone) List(2, zone);
List* list = new (zone->New(sizeof(List))) List(zone);
if (singleton() < value) {
list->Add(singleton(), zone);
list->Add(value, zone);
list->push_back(singleton());
list->push_back(value);
} else {
list->Add(value, zone);
list->Add(singleton(), zone);
list->push_back(value);
list->push_back(singleton());
}
DCHECK(IsAligned(bit_cast<intptr_t>(list), kPointerAlignment));
data_ = bit_cast<intptr_t>(list) | kListTag;
} else {
DCHECK_EQ(kListTag, data_ & kTagMask);
List const* const old_list = list();
for (int i = 0; i < old_list->length(); ++i) {
for (size_t i = 0; i < old_list->size(); ++i) {
if (old_list->at(i) == value) return;
if (old_list->at(i) > value) break;
}
List* new_list = new (zone) List(old_list->length() + 1, zone);
int i = 0;
for (; i < old_list->length(); ++i) {
List* new_list = new (zone->New(sizeof(List))) List(zone);
new_list->reserve(old_list->size() + 1);
size_t i = 0;
for (; i < old_list->size(); ++i) {
if (old_list->at(i) > value) break;
new_list->Add(old_list->at(i), zone);
new_list->push_back(old_list->at(i));
}
new_list->Add(value, zone);
for (; i < old_list->length(); ++i) {
new_list->Add(old_list->at(i), zone);
new_list->push_back(value);
for (; i < old_list->size(); ++i) {
new_list->push_back(old_list->at(i));
}
DCHECK_EQ(old_list->length() + 1, new_list->length());
DCHECK_EQ(old_list->size() + 1, new_list->size());
DCHECK(IsAligned(bit_cast<intptr_t>(new_list), kPointerAlignment));
data_ = bit_cast<intptr_t>(new_list) | kListTag;
}
......@@ -85,13 +87,18 @@ class ZoneHandleSet final {
if (other.data_ == kEmptyTag) return true;
if ((data_ & kTagMask) == kSingletonTag) return false;
DCHECK_EQ(kListTag, data_ & kTagMask);
List const* cached_list = list();
if ((other.data_ & kTagMask) == kSingletonTag) {
return list()->Contains(other.singleton());
return std::find(cached_list->begin(), cached_list->end(),
other.singleton()) != cached_list->end();
}
DCHECK_EQ(kListTag, other.data_ & kTagMask);
// TODO(bmeurer): Optimize this case.
for (int i = 0; i < other.list()->length(); ++i) {
if (!list()->Contains(other.list()->at(i))) return false;
for (size_t i = 0; i < other.list()->size(); ++i) {
if (std::find(cached_list->begin(), cached_list->end(),
other.list()->at(i)) == cached_list->end()) {
return false;
}
}
return true;
}
......@@ -102,7 +109,8 @@ class ZoneHandleSet final {
return singleton() == bit_cast<T**>(other.address());
}
DCHECK_EQ(kListTag, data_ & kTagMask);
return list()->Contains(bit_cast<T**>(other.address()));
return std::find(list()->begin(), list()->end(),
bit_cast<T**>(other.address())) != list()->end();
}
void remove(Handle<T> handle, Zone* zone) {
......@@ -124,8 +132,8 @@ class ZoneHandleSet final {
(rhs.data_ & kTagMask) == kListTag) {
List const* const lhs_list = lhs.list();
List const* const rhs_list = rhs.list();
if (lhs_list->length() == rhs_list->length()) {
for (int i = 0; i < lhs_list->length(); ++i) {
if (lhs_list->size() == rhs_list->size()) {
for (size_t i = 0; i < lhs_list->size(); ++i) {
if (lhs_list->at(i) != rhs_list->at(i)) return false;
}
return true;
......@@ -148,7 +156,7 @@ class ZoneHandleSet final {
inline const_iterator end() const;
private:
typedef ZoneList<T**> List;
typedef ZoneVector<T**> List;
List const* list() const {
DCHECK_EQ(kListTag, data_ & kTagMask);
......
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