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

Unified Diff: src/api.cc

Issue 1965593002: Fix Map::AsArray to properly iterate over the backing store (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Micro-optimized Created 4 years, 7 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 | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 2695b3e0955677790388bd907b7e29a4f6e79717..49b078c51030f4ea7a0dada06e81707676567170 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6367,14 +6367,22 @@ Local<Array> Map::AsArray() const {
LOG_API(isolate, "Map::AsArray");
ENTER_V8(isolate);
i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(obj->table()));
- int size = table->NumberOfElements();
- int length = size * 2;
+ int length = table->NumberOfElements() * 2;
i::Handle<i::FixedArray> result = factory->NewFixedArray(length);
- for (int i = 0; i < size; ++i) {
- if (table->KeyAt(i)->IsTheHole()) continue;
- result->set(i * 2, table->KeyAt(i));
- result->set(i * 2 + 1, table->ValueAt(i));
+ int result_index = 0;
+ {
+ i::DisallowHeapAllocation no_gc;
+ int capacity = table->UsedCapacity();
+ i::Oddball* the_hole = isolate->heap()->the_hole_value();
+ for (int i = 0; i < capacity; ++i) {
+ i::Object* key = table->KeyAt(i);
+ if (key == the_hole) continue;
+ result->set(result_index++, key);
+ result->set(result_index++, table->ValueAt(i));
+ }
}
+ DCHECK_EQ(result_index, result->length());
+ DCHECK_EQ(result_index, length);
i::Handle<i::JSArray> result_array =
factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length);
return Utils::ToLocal(result_array);
@@ -6451,13 +6459,16 @@ Local<Array> Set::AsArray() const {
LOG_API(isolate, "Set::AsArray");
ENTER_V8(isolate);
i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(obj->table()));
- int capacity = table->UsedCapacity();
int length = table->NumberOfElements();
i::Handle<i::FixedArray> result = factory->NewFixedArray(length);
int result_index = 0;
- for (int i = 0; i < capacity; ++i) {
- i::Object* key = table->KeyAt(i);
- if (!key->IsTheHole()) {
+ {
+ i::DisallowHeapAllocation no_gc;
+ int capacity = table->UsedCapacity();
+ i::Oddball* the_hole = isolate->heap()->the_hole_value();
+ for (int i = 0; i < capacity; ++i) {
+ i::Object* key = table->KeyAt(i);
+ if (key == the_hole) continue;
result->set(result_index++, key);
}
}
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698