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

Side by Side Diff: src/objects.h

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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_OBJECTS_H_ 5 #ifndef V8_OBJECTS_H_
6 #define V8_OBJECTS_H_ 6 #define V8_OBJECTS_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 9
10 #include "src/allocation.h" 10 #include "src/allocation.h"
(...skipping 3862 matching lines...) Expand 10 before | Expand all | Expand 10 after
3873 static Handle<Derived> EnsureGrowable(Handle<Derived> table); 3873 static Handle<Derived> EnsureGrowable(Handle<Derived> table);
3874 3874
3875 // Returns an OrderedHashTable (possibly |table|) that's shrunken 3875 // Returns an OrderedHashTable (possibly |table|) that's shrunken
3876 // if possible. 3876 // if possible.
3877 static Handle<Derived> Shrink(Handle<Derived> table); 3877 static Handle<Derived> Shrink(Handle<Derived> table);
3878 3878
3879 // Returns a new empty OrderedHashTable and records the clearing so that 3879 // Returns a new empty OrderedHashTable and records the clearing so that
3880 // exisiting iterators can be updated. 3880 // exisiting iterators can be updated.
3881 static Handle<Derived> Clear(Handle<Derived> table); 3881 static Handle<Derived> Clear(Handle<Derived> table);
3882 3882
3883 // Returns an OrderedHashTable (possibly |table|) where |key| has been
3884 // removed.
3885 static Handle<Derived> Remove(Handle<Derived> table, Handle<Object> key,
3886 bool* was_present);
3887
3888 // Returns kNotFound if the key isn't present.
3889 int FindEntry(Handle<Object> key, int hash);
3890
3891 // Like the above, but doesn't require the caller to provide a hash.
3892 int FindEntry(Handle<Object> key);
3893
3894 int NumberOfElements() { 3883 int NumberOfElements() {
3895 return Smi::cast(get(kNumberOfElementsIndex))->value(); 3884 return Smi::cast(get(kNumberOfElementsIndex))->value();
3896 } 3885 }
3897 3886
3898 int NumberOfDeletedElements() { 3887 int NumberOfDeletedElements() {
3899 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); 3888 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
3900 } 3889 }
3901 3890
3902 int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } 3891 int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); }
3903 3892
3904 int NumberOfBuckets() { 3893 int NumberOfBuckets() {
3905 return Smi::cast(get(kNumberOfBucketsIndex))->value(); 3894 return Smi::cast(get(kNumberOfBucketsIndex))->value();
3906 } 3895 }
3907 3896
3908 // Returns the index into the data table where the new entry
3909 // should be placed. The table is assumed to have enough space
3910 // for a new entry.
3911 int AddEntry(int hash);
3912
3913 // Removes the entry, and puts the_hole in entrysize pointers
3914 // (leaving the hash table chain intact).
3915 void RemoveEntry(int entry);
3916
3917 // Returns an index into |this| for the given entry. 3897 // Returns an index into |this| for the given entry.
3918 int EntryToIndex(int entry) { 3898 int EntryToIndex(int entry) {
3919 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); 3899 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize);
3920 } 3900 }
3921 3901
3922 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } 3902 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
3923 3903
3924 bool IsObsolete() { 3904 bool IsObsolete() {
3925 return !get(kNextTableIndex)->IsSmi(); 3905 return !get(kNextTableIndex)->IsSmi();
3926 } 3906 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3977 } 3957 }
3978 3958
3979 void SetNumberOfDeletedElements(int num) { 3959 void SetNumberOfDeletedElements(int num) {
3980 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); 3960 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num));
3981 } 3961 }
3982 3962
3983 int Capacity() { 3963 int Capacity() {
3984 return NumberOfBuckets() * kLoadFactor; 3964 return NumberOfBuckets() * kLoadFactor;
3985 } 3965 }
3986 3966
3987 // Returns the next entry for the given entry.
3988 int ChainAt(int entry) {
3989 return Smi::cast(get(EntryToIndex(entry) + kChainOffset))->value();
3990 }
3991
3992 int HashToBucket(int hash) {
3993 return hash & (NumberOfBuckets() - 1);
3994 }
3995
3996 int HashToEntry(int hash) {
3997 int bucket = HashToBucket(hash);
3998 return Smi::cast(get(kHashTableStartIndex + bucket))->value();
3999 }
4000
4001 void SetNextTable(Derived* next_table) { 3967 void SetNextTable(Derived* next_table) {
4002 set(kNextTableIndex, next_table); 3968 set(kNextTableIndex, next_table);
4003 } 3969 }
4004 3970
4005 void SetRemovedIndexAt(int index, int removed_index) { 3971 void SetRemovedIndexAt(int index, int removed_index) {
4006 return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index)); 3972 return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index));
4007 } 3973 }
4008 3974
4009 static const int kRemovedHolesIndex = kHashTableStartIndex; 3975 static const int kRemovedHolesIndex = kHashTableStartIndex;
4010 3976
4011 static const int kMaxCapacity = 3977 static const int kMaxCapacity =
4012 (FixedArray::kMaxLength - kHashTableStartIndex) 3978 (FixedArray::kMaxLength - kHashTableStartIndex)
4013 / (1 + (kEntrySize * kLoadFactor)); 3979 / (1 + (kEntrySize * kLoadFactor));
4014 }; 3980 };
4015 3981
4016 3982
4017 class JSSetIterator; 3983 class JSSetIterator;
4018 3984
4019 3985
4020 class OrderedHashSet: public OrderedHashTable< 3986 class OrderedHashSet: public OrderedHashTable<
4021 OrderedHashSet, JSSetIterator, 1> { 3987 OrderedHashSet, JSSetIterator, 1> {
4022 public: 3988 public:
4023 DECLARE_CAST(OrderedHashSet) 3989 DECLARE_CAST(OrderedHashSet)
4024
4025 bool Contains(Handle<Object> key);
4026 static Handle<OrderedHashSet> Add(
4027 Handle<OrderedHashSet> table, Handle<Object> key);
4028 }; 3990 };
4029 3991
4030 3992
4031 class JSMapIterator; 3993 class JSMapIterator;
4032 3994
4033 3995
4034 class OrderedHashMap:public OrderedHashTable< 3996 class OrderedHashMap: public OrderedHashTable<
4035 OrderedHashMap, JSMapIterator, 2> { 3997 OrderedHashMap, JSMapIterator, 2> {
4036 public: 3998 public:
4037 DECLARE_CAST(OrderedHashMap) 3999 DECLARE_CAST(OrderedHashMap)
4038 4000
4039 Object* Lookup(Handle<Object> key);
4040 static Handle<OrderedHashMap> Put(
4041 Handle<OrderedHashMap> table,
4042 Handle<Object> key,
4043 Handle<Object> value);
4044
4045 Object* ValueAt(int entry) { 4001 Object* ValueAt(int entry) {
4046 return get(EntryToIndex(entry) + kValueOffset); 4002 return get(EntryToIndex(entry) + kValueOffset);
4047 } 4003 }
4048 4004
4049 static const int kValueOffset = 1; 4005 static const int kValueOffset = 1;
4050 }; 4006 };
4051 4007
4052 4008
4053 template <int entrysize> 4009 template <int entrysize>
4054 class WeakHashTableShape : public BaseShape<Handle<Object> > { 4010 class WeakHashTableShape : public BaseShape<Handle<Object> > {
(...skipping 6936 matching lines...) Expand 10 before | Expand all | Expand 10 after
10991 } else { 10947 } else {
10992 value &= ~(1 << bit_position); 10948 value &= ~(1 << bit_position);
10993 } 10949 }
10994 return value; 10950 return value;
10995 } 10951 }
10996 }; 10952 };
10997 10953
10998 } } // namespace v8::internal 10954 } } // namespace v8::internal
10999 10955
11000 #endif // V8_OBJECTS_H_ 10956 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698