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

Unified Diff: src/objects.cc

Issue 355663002: Optimize Map/Set.prototype.forEach (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Cleanup Created 6 years, 6 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 | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 87aa471e34b99e7ed575a61764caa4e0ce02bef4..2d3f0f878a1e4cc4a715d4f8c75717071b9763fb 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -16229,47 +16229,14 @@ Handle<OrderedHashMap> OrderedHashMap::Put(Handle<OrderedHashMap> table,
template<class Derived, class TableType>
-Handle<JSObject> OrderedHashTableIterator<Derived, TableType>::Next(
- Handle<Derived> iterator) {
- Isolate* isolate = iterator->GetIsolate();
- Factory* factory = isolate->factory();
-
- Handle<Object> maybe_table(iterator->table(), isolate);
- if (!maybe_table->IsUndefined()) {
- iterator->Transition();
-
- Handle<TableType> table(TableType::cast(iterator->table()), isolate);
- int index = Smi::cast(iterator->index())->value();
- int used_capacity = table->UsedCapacity();
-
- while (index < used_capacity && table->KeyAt(index)->IsTheHole()) {
- index++;
- }
-
- if (index < used_capacity) {
- int entry_index = table->EntryToIndex(index);
- Handle<Object> value =
- Derived::ValueForKind(iterator, entry_index);
- iterator->set_index(Smi::FromInt(index + 1));
- return factory->NewIteratorResultObject(value, false);
- }
-
- iterator->set_table(iterator->GetHeap()->undefined_value());
- }
-
- return factory->NewIteratorResultObject(factory->undefined_value(), true);
-}
-
-
-template<class Derived, class TableType>
void OrderedHashTableIterator<Derived, TableType>::Transition() {
- Isolate* isolate = GetIsolate();
- Handle<TableType> table(TableType::cast(this->table()), isolate);
+ DisallowHeapAllocation no_allocation;
+ TableType* table = TableType::cast(this->table());
if (!table->IsObsolete()) return;
int index = Smi::cast(this->index())->value();
while (table->IsObsolete()) {
- Handle<TableType> next_table(table->NextTable(), isolate);
+ TableType* next_table = table->NextTable();
if (index > 0) {
int nod = table->NumberOfDeletedElements();
@@ -16290,82 +16257,80 @@ void OrderedHashTableIterator<Derived, TableType>::Transition() {
table = next_table;
}
- set_table(*table);
+ set_table(table);
set_index(Smi::FromInt(index));
}
-template Handle<JSObject>
-OrderedHashTableIterator<JSSetIterator, OrderedHashSet>::Next(
- Handle<JSSetIterator> iterator);
-
-template void
-OrderedHashTableIterator<JSSetIterator, OrderedHashSet>::Transition();
+template<class Derived, class TableType>
+bool OrderedHashTableIterator<Derived, TableType>::HasMore() {
+ DisallowHeapAllocation no_allocation;
+ if (this->table()->IsUndefined()) return false;
+ Transition();
-template Handle<JSObject>
-OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::Next(
- Handle<JSMapIterator> iterator);
+ TableType* table = TableType::cast(this->table());
+ int index = Smi::cast(this->index())->value();
+ int used_capacity = table->UsedCapacity();
-template void
-OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::Transition();
+ while (index < used_capacity && table->KeyAt(index)->IsTheHole()) {
+ index++;
+ }
+ set_index(Smi::FromInt(index));
-Handle<Object> JSSetIterator::ValueForKind(
- Handle<JSSetIterator> iterator, int entry_index) {
- int kind = iterator->kind()->value();
- // Set.prototype only has values and entries.
- ASSERT(kind == kKindValues || kind == kKindEntries);
+ if (index < used_capacity) return true;
- Isolate* isolate = iterator->GetIsolate();
- Factory* factory = isolate->factory();
+ set_table(GetHeap()->undefined_value());
+ return false;
+}
- Handle<OrderedHashSet> table(
- OrderedHashSet::cast(iterator->table()), isolate);
- Handle<Object> value = Handle<Object>(table->get(entry_index), isolate);
- if (kind == kKindEntries) {
- Handle<FixedArray> array = factory->NewFixedArray(2);
- array->set(0, *value);
- array->set(1, *value);
- return factory->NewJSArrayWithElements(array);
+template<class Derived, class TableType>
+Smi* OrderedHashTableIterator<Derived, TableType>::Next(JSArray* value_array) {
+ DisallowHeapAllocation no_allocation;
+ if (HasMore()) {
+ FixedArray* array = FixedArray::cast(value_array->elements());
+ static_cast<Derived*>(this)->PopulateValueArray(array);
+ MoveNext();
+ return kind();
}
-
- return value;
+ return Smi::FromInt(0);
}
-Handle<Object> JSMapIterator::ValueForKind(
- Handle<JSMapIterator> iterator, int entry_index) {
- int kind = iterator->kind()->value();
- ASSERT(kind == kKindKeys || kind == kKindValues || kind == kKindEntries);
+template Smi*
+OrderedHashTableIterator<JSSetIterator, OrderedHashSet>::Next(
+ JSArray* value_array);
- Isolate* isolate = iterator->GetIsolate();
- Factory* factory = isolate->factory();
+template bool
+OrderedHashTableIterator<JSSetIterator, OrderedHashSet>::HasMore();
- Handle<OrderedHashMap> table(
- OrderedHashMap::cast(iterator->table()), isolate);
+template void
+OrderedHashTableIterator<JSSetIterator, OrderedHashSet>::MoveNext();
- switch (kind) {
- case kKindKeys:
- return Handle<Object>(table->get(entry_index), isolate);
+template Object*
+OrderedHashTableIterator<JSSetIterator, OrderedHashSet>::CurrentKey();
- case kKindValues:
- return Handle<Object>(table->get(entry_index + 1), isolate);
+template void
+OrderedHashTableIterator<JSSetIterator, OrderedHashSet>::Transition();
- case kKindEntries: {
- Handle<Object> key(table->get(entry_index), isolate);
- Handle<Object> value(table->get(entry_index + 1), isolate);
- Handle<FixedArray> array = factory->NewFixedArray(2);
- array->set(0, *key);
- array->set(1, *value);
- return factory->NewJSArrayWithElements(array);
- }
- }
- UNREACHABLE();
- return factory->undefined_value();
-}
+template Smi*
+OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::Next(
+ JSArray* value_array);
+
+template bool
+OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::HasMore();
+
+template void
+OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::MoveNext();
+
+template Object*
+OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::CurrentKey();
+
+template void
+OrderedHashTableIterator<JSMapIterator, OrderedHashMap>::Transition();
DeclaredAccessorDescriptorIterator::DeclaredAccessorDescriptorIterator(
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698