Chromium Code Reviews| Index: src/api.cc |
| diff --git a/src/api.cc b/src/api.cc |
| index 2695b3e0955677790388bd907b7e29a4f6e79717..9ed18887a903ece61fb55877f6777850fa492ecf 100644 |
| --- a/src/api.cc |
| +++ b/src/api.cc |
| @@ -6367,14 +6367,18 @@ 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 capacity = table->UsedCapacity(); |
| + int result_index = 0; |
| + for (int i = 0; i < capacity; ++i) { |
| + i::Object* key = table->KeyAt(i); |
| + if (key->IsTheHole()) continue; |
|
Camillo Bruni
2016/05/10 06:50:59
nit: IsTheHole in a loop is rather slow, keep a lo
adamk
2016/05/10 17:19:24
Done, and added a DisallowHeapAllocation for good
|
| + 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); |