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

Side by Side Diff: src/objects.h

Issue 1397063002: [runtime] Fancify KeyAccumulator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: documentation + cleanup Created 5 years, 2 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
« no previous file with comments | « src/elements.cc ('k') | src/objects.cc » ('j') | src/objects.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 class AllocationSite; 847 class AllocationSite;
848 class AllocationSiteCreationContext; 848 class AllocationSiteCreationContext;
849 class AllocationSiteUsageContext; 849 class AllocationSiteUsageContext;
850 class Cell; 850 class Cell;
851 class ConsString; 851 class ConsString;
852 class ElementsAccessor; 852 class ElementsAccessor;
853 class FixedArrayBase; 853 class FixedArrayBase;
854 class FunctionLiteral; 854 class FunctionLiteral;
855 class GlobalObject; 855 class GlobalObject;
856 class JSBuiltinsObject; 856 class JSBuiltinsObject;
857 class KeyAccumulator;
857 class LayoutDescriptor; 858 class LayoutDescriptor;
858 class LiteralsArray; 859 class LiteralsArray;
859 class LookupIterator; 860 class LookupIterator;
860 class ObjectHashTable; 861 class ObjectHashTable;
861 class ObjectVisitor; 862 class ObjectVisitor;
862 class PropertyCell; 863 class PropertyCell;
863 class SafepointEntry; 864 class SafepointEntry;
864 class SharedFunctionInfo; 865 class SharedFunctionInfo;
865 class StringStream; 866 class StringStream;
866 class TypeFeedbackInfo; 867 class TypeFeedbackInfo;
(...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after
2189 PropertyAttributes filter = NONE); 2190 PropertyAttributes filter = NONE);
2190 2191
2191 // Returns the number of properties on this object filtering out properties 2192 // Returns the number of properties on this object filtering out properties
2192 // with the specified attributes (ignoring interceptors). 2193 // with the specified attributes (ignoring interceptors).
2193 int NumberOfOwnElements(PropertyAttributes filter); 2194 int NumberOfOwnElements(PropertyAttributes filter);
2194 // Returns the number of enumerable elements (ignoring interceptors). 2195 // Returns the number of enumerable elements (ignoring interceptors).
2195 int NumberOfEnumElements(); 2196 int NumberOfEnumElements();
2196 // Returns the number of elements on this object filtering out elements 2197 // Returns the number of elements on this object filtering out elements
2197 // with the specified attributes (ignoring interceptors). 2198 // with the specified attributes (ignoring interceptors).
2198 int GetOwnElementKeys(FixedArray* storage, PropertyAttributes filter); 2199 int GetOwnElementKeys(FixedArray* storage, PropertyAttributes filter);
2200 static void CollectOwnElementKeys(Handle<JSObject> object,
2201 KeyAccumulator* keys,
2202 PropertyAttributes filter);
2199 // Count and fill in the enumerable elements into storage. 2203 // Count and fill in the enumerable elements into storage.
2200 // (storage->length() == NumberOfEnumElements()). 2204 // (storage->length() == NumberOfEnumElements()).
2201 // If storage is NULL, will count the elements without adding 2205 // If storage is NULL, will count the elements without adding
2202 // them to any storage. 2206 // them to any storage.
2203 // Returns the number of enumerable elements. 2207 // Returns the number of enumerable elements.
2204 int GetEnumElementKeys(FixedArray* storage); 2208 int GetEnumElementKeys(FixedArray* storage);
2205 2209
2206 static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, 2210 static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
2207 bool cache_result); 2211 bool cache_result);
2208 2212
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3323 // Returns true if the dictionary contains any elements that are non-writable, 3327 // Returns true if the dictionary contains any elements that are non-writable,
3324 // non-configurable, non-enumerable, or have getters/setters. 3328 // non-configurable, non-enumerable, or have getters/setters.
3325 bool HasComplexElements(); 3329 bool HasComplexElements();
3326 3330
3327 enum SortMode { UNSORTED, SORTED }; 3331 enum SortMode { UNSORTED, SORTED };
3328 3332
3329 // Fill in details for properties into storage. 3333 // Fill in details for properties into storage.
3330 // Returns the number of properties added. 3334 // Returns the number of properties added.
3331 int CopyKeysTo(FixedArray* storage, int index, PropertyAttributes filter, 3335 int CopyKeysTo(FixedArray* storage, int index, PropertyAttributes filter,
3332 SortMode sort_mode); 3336 SortMode sort_mode);
3337 static void CopyElementKeysTo(Handle<Derived> dictionary,
3338 KeyAccumulator* keys, PropertyAttributes filter,
3339 uint32_t start);
3333 3340
3334 // Copies enumerable keys to preallocated fixed array. 3341 // Copies enumerable keys to preallocated fixed array.
3335 void CopyEnumKeysTo(FixedArray* storage); 3342 void CopyEnumKeysTo(FixedArray* storage);
3336 3343
3337 // Accessors for next enumeration index. 3344 // Accessors for next enumeration index.
3338 void SetNextEnumerationIndex(int index) { 3345 void SetNextEnumerationIndex(int index) {
3339 DCHECK(index != 0); 3346 DCHECK(index != 0);
3340 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); 3347 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
3341 } 3348 }
3342 3349
(...skipping 7310 matching lines...) Expand 10 before | Expand all | Expand 10 after
10653 if (v) { 10660 if (v) {
10654 value |= (1 << bit_position); 10661 value |= (1 << bit_position);
10655 } else { 10662 } else {
10656 value &= ~(1 << bit_position); 10663 value &= ~(1 << bit_position);
10657 } 10664 }
10658 return value; 10665 return value;
10659 } 10666 }
10660 }; 10667 };
10661 10668
10662 10669
10670 enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC };
10671
10672
10673 enum GetKeysConversion { CONVERT_TO_STRING, KEEP_NUMBERS };
10674
10675
10663 class KeyAccumulator final BASE_EMBEDDED { 10676 class KeyAccumulator final BASE_EMBEDDED {
10664 public: 10677 public:
10665 explicit KeyAccumulator(Isolate* isolate) : isolate_(isolate), length_(0) {} 10678 explicit KeyAccumulator(Isolate* isolate,
10679 KeyFilter filter = KeyFilter::SKIP_SYMBOLS)
10680 : isolate_(isolate), filter_(filter), length_(0), levelLength_(0) {}
10666 10681
10667 void AddKey(Handle<Object> key, int check_limit); 10682 bool AddKey(uint32_t key);
10668 void AddKeys(Handle<FixedArray> array, KeyFilter filter); 10683 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT);
10669 void AddKeys(Handle<JSObject> array, KeyFilter filter); 10684 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT);
10670 void PrepareForComparisons(int count); 10685 void AddKeys(Handle<FixedArray> array,
10671 Handle<FixedArray> GetKeys(); 10686 AddKeyConversion convert = DO_NOT_CONVERT);
10687 void AddKeys(Handle<JSObject> array,
10688 AddKeyConversion convert = DO_NOT_CONVERT);
10689 void AddKeysFromProxy(Handle<JSObject> array);
10690 // Jump to the next level, pushing the current |levelLength_| to
10691 // |levelLengths_| and adding a new list to |elements_|.
10692 void NextPrototype();
10693 void SortCurrentElementsList();
10694 Handle<FixedArray> GetKeys(GetKeysConversion convert = CONVERT_TO_STRING);
10672 10695
10673 int GetLength() { return length_; }
10674 10696
10675 private: 10697 private:
10676 void EnsureCapacity(int capacity); 10698 Isolate* isolate_;
10677 void Grow(); 10699 KeyFilter filter_;
10700 // |elements_| contains the sorted element keys (indices) per level.
10701 List<List<uint32_t>*> elements_;
10702 // |protoLengths_| contains the total number of keys (elements + properties)
10703 // per level. Negative values mark counts for a level with keys from a proxy.
10704 List<int> levelLengths_;
10705 // |properties_| contains the property keys per level in insertion order.
10706 Handle<OrderedHashSet> properties_;
10707 // |length_| keeps track of the total number of all element and property keys.
10708 int length_;
10709 // |levelLength_| keeps track of the total number of keys
10710 // (elements + properties) in the current level.
10711 int levelLength_;
10678 10712
10679 Isolate* isolate_;
10680 Handle<FixedArray> keys_;
10681 Handle<OrderedHashSet> set_;
10682 int length_;
10683 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); 10713 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator);
10684 }; 10714 };
10685 10715
10686 } // NOLINT, false-positive due to second-order macros. 10716 } // NOLINT, false-positive due to second-order macros.
10687 } // NOLINT, false-positive due to second-order macros. 10717 } // NOLINT, false-positive due to second-order macros.
10688 10718
10689 #endif // V8_OBJECTS_H_ 10719 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/elements.cc ('k') | src/objects.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698