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

Unified Diff: src/api.cc

Issue 1157843006: Flatten the Arrays returned and consumed by the v8::Map API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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 | « include/v8.h ('k') | src/collection.js » ('j') | src/collection.js » ('J')
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 6ecdb4d4a207a2bcc6308d99773d363252456073..985daacef4d2175280681a3174cf9a5f2332b03b 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6272,17 +6272,13 @@ Local<Array> Map::AsArray() const {
LOG_API(isolate, "Map::AsArray");
ENTER_V8(isolate);
i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(obj->table()));
- int length = table->NumberOfElements();
+ int size = table->NumberOfElements();
+ int length = size * 2;
i::Handle<i::FixedArray> result = factory->NewFixedArray(length);
- for (int i = 0; i < length; ++i) {
+ for (int i = 0; i < size; ++i) {
if (table->KeyAt(i)->IsTheHole()) continue;
- i::HandleScope handle_scope(isolate);
- i::Handle<i::FixedArray> entry = factory->NewFixedArray(2);
- entry->set(0, table->KeyAt(i));
- entry->set(1, table->ValueAt(i));
- i::Handle<i::JSArray> entry_array =
- factory->NewJSArrayWithElements(entry, i::FAST_ELEMENTS, 2);
- result->set(i, *entry_array);
+ result->set(i * 2, table->KeyAt(i));
+ result->set(i * 2 + 1, table->ValueAt(i));
}
i::Handle<i::JSArray> result_array =
factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length);
« no previous file with comments | « include/v8.h ('k') | src/collection.js » ('j') | src/collection.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698