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

Unified Diff: src/runtime/runtime-collections.cc

Issue 947683002: Reimplement Maps and Sets in JS (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Disable one more test Created 5 years, 10 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
Index: src/runtime/runtime-collections.cc
diff --git a/src/runtime/runtime-collections.cc b/src/runtime/runtime-collections.cc
index ffffbdd2f2d601a3c60c5f0061653b5cddd7523d..5bf97799c108b61ae662c6f6d3e8ed37e8e44007 100644
--- a/src/runtime/runtime-collections.cc
+++ b/src/runtime/runtime-collections.cc
@@ -11,68 +11,110 @@
namespace v8 {
namespace internal {
-RUNTIME_FUNCTION(Runtime_SetInitialize) {
+
+RUNTIME_FUNCTION(Runtime_StringHash) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
- CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
- Handle<OrderedHashSet> table = isolate->factory()->NewOrderedHashSet();
- holder->set_table(*table);
- return *holder;
+ CONVERT_ARG_HANDLE_CHECKED(String, string, 0);
+ return Smi::FromInt(string->Hash());
}
-RUNTIME_FUNCTION(Runtime_SetAdd) {
+RUNTIME_FUNCTION(Runtime_SmiHash) {
HandleScope scope(isolate);
+ DCHECK(args.length() == 1);
+ return args[0]->GetHash();
+}
+
+
+RUNTIME_FUNCTION(Runtime_FixedArrayGet) {
+ SealHandleScope shs(isolate);
DCHECK(args.length() == 2);
- CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
- CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
- Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
- table = OrderedHashSet::Add(table, key);
- holder->set_table(*table);
- return *holder;
+ CONVERT_ARG_CHECKED(FixedArray, object, 0);
+ CONVERT_SMI_ARG_CHECKED(index, 1);
+ return object->get(index);
}
-RUNTIME_FUNCTION(Runtime_SetHas) {
- HandleScope scope(isolate);
+RUNTIME_FUNCTION(Runtime_FixedArraySet) {
+ SealHandleScope shs(isolate);
+ DCHECK(args.length() == 3);
+ CONVERT_ARG_CHECKED(FixedArray, object, 0);
+ CONVERT_SMI_ARG_CHECKED(index, 1);
+ CONVERT_ARG_CHECKED(Object, value, 2);
+ object->set(index, value);
+ return isolate->heap()->undefined_value();
+}
+
+
+RUNTIME_FUNCTION(Runtime_FixedArraySetTheHole) {
+ SealHandleScope shs(isolate);
DCHECK(args.length() == 2);
+ CONVERT_ARG_CHECKED(FixedArray, object, 0);
+ CONVERT_SMI_ARG_CHECKED(index, 1);
+ object->set_the_hole(index);
+ return isolate->heap()->undefined_value();
+}
+
+
+RUNTIME_FUNCTION(Runtime_JSCollectionGetTable) {
+ SealHandleScope shs(isolate);
+ DCHECK(args.length() == 1);
+ CONVERT_ARG_CHECKED(JSObject, object, 0);
+ RUNTIME_ASSERT(object->IsJSSet() || object->IsJSMap());
+ return static_cast<JSCollection*>(object)->table();
+}
+
+
+RUNTIME_FUNCTION(Runtime_GenericHash) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
+ Handle<Smi> hash = Object::GetOrCreateHash(isolate, object);
+ return *hash;
+}
+
+
+RUNTIME_FUNCTION(Runtime_SetInitialize) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
- CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
- Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
- return isolate->heap()->ToBoolean(table->Contains(key));
+ Handle<OrderedHashSet> table = isolate->factory()->NewOrderedHashSet();
+ holder->set_table(*table);
+ return *holder;
}
-RUNTIME_FUNCTION(Runtime_SetDelete) {
+RUNTIME_FUNCTION(Runtime_SetGrow) {
HandleScope scope(isolate);
- DCHECK(args.length() == 2);
+ DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
- CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
- bool was_present = false;
- table = OrderedHashSet::Remove(table, key, &was_present);
+ table = OrderedHashSet::EnsureGrowable(table);
holder->set_table(*table);
- return isolate->heap()->ToBoolean(was_present);
+ return isolate->heap()->undefined_value();
}
-RUNTIME_FUNCTION(Runtime_SetClear) {
+RUNTIME_FUNCTION(Runtime_SetShrink) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
- table = OrderedHashSet::Clear(table);
+ table = OrderedHashSet::Shrink(table);
holder->set_table(*table);
return isolate->heap()->undefined_value();
}
-RUNTIME_FUNCTION(Runtime_SetGetSize) {
+RUNTIME_FUNCTION(Runtime_SetClear) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
- return Smi::FromInt(table->NumberOfElements());
+ table = OrderedHashSet::Clear(table);
+ holder->set_table(*table);
+ return isolate->heap()->undefined_value();
}
@@ -141,39 +183,14 @@ RUNTIME_FUNCTION(Runtime_MapInitialize) {
}
-RUNTIME_FUNCTION(Runtime_MapGet) {
- HandleScope scope(isolate);
- DCHECK(args.length() == 2);
- CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
- CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
- Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
- Handle<Object> lookup(table->Lookup(key), isolate);
- return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup;
-}
-
-
-RUNTIME_FUNCTION(Runtime_MapHas) {
- HandleScope scope(isolate);
- DCHECK(args.length() == 2);
- CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
- CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
- Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
- Handle<Object> lookup(table->Lookup(key), isolate);
- return isolate->heap()->ToBoolean(!lookup->IsTheHole());
-}
-
-
-RUNTIME_FUNCTION(Runtime_MapDelete) {
+RUNTIME_FUNCTION(Runtime_MapShrink) {
HandleScope scope(isolate);
- DCHECK(args.length() == 2);
+ DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
- CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
- bool was_present = false;
- Handle<OrderedHashMap> new_table =
- OrderedHashMap::Remove(table, key, &was_present);
- holder->set_table(*new_table);
- return isolate->heap()->ToBoolean(was_present);
+ table = OrderedHashMap::Shrink(table);
+ holder->set_table(*table);
+ return isolate->heap()->undefined_value();
}
@@ -188,25 +205,14 @@ RUNTIME_FUNCTION(Runtime_MapClear) {
}
-RUNTIME_FUNCTION(Runtime_MapSet) {
- HandleScope scope(isolate);
- DCHECK(args.length() == 3);
- CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
- CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
- CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
- Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
- Handle<OrderedHashMap> new_table = OrderedHashMap::Put(table, key, value);
- holder->set_table(*new_table);
- return *holder;
-}
-
-
-RUNTIME_FUNCTION(Runtime_MapGetSize) {
+RUNTIME_FUNCTION(Runtime_MapGrow) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()));
- return Smi::FromInt(table->NumberOfElements());
+ table = OrderedHashMap::EnsureGrowable(table);
+ holder->set_table(*table);
+ return isolate->heap()->undefined_value();
}
« src/objects.cc ('K') | « src/runtime/runtime.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698