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

Side by Side Diff: src/key-accumulator.h

Issue 1492653004: [cleanup] Introduce PropertyFilter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: windows ♥ Created 5 years 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/json-stringifier.h ('k') | src/key-accumulator.cc » ('j') | no next file with comments »
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_KEY_ACCUMULATOR_H_ 5 #ifndef V8_KEY_ACCUMULATOR_H_
6 #define V8_KEY_ACCUMULATOR_H_ 6 #define V8_KEY_ACCUMULATOR_H_
7 7
8 #include "src/isolate.h" 8 #include "src/isolate.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 10
(...skipping 13 matching lines...) Expand all
24 // collected in |string_properties_|, a single OrderedHashSet (similar for 24 // collected in |string_properties_|, a single OrderedHashSet (similar for
25 // Symbols in |symbol_properties_|. To separate the keys per level later when 25 // Symbols in |symbol_properties_|. To separate the keys per level later when
26 // assembling the final list, |levelLengths_| keeps track of the number of 26 // assembling the final list, |levelLengths_| keeps track of the number of
27 // String and Symbol keys per level. 27 // String and Symbol keys per level.
28 // 28 //
29 // Only unique keys are kept by the KeyAccumulator, strings are stored in a 29 // Only unique keys are kept by the KeyAccumulator, strings are stored in a
30 // HashSet for inexpensive lookups. Integer keys are kept in sorted lists which 30 // HashSet for inexpensive lookups. Integer keys are kept in sorted lists which
31 // are more compact and allow for reasonably fast includes check. 31 // are more compact and allow for reasonably fast includes check.
32 class KeyAccumulator final BASE_EMBEDDED { 32 class KeyAccumulator final BASE_EMBEDDED {
33 public: 33 public:
34 explicit KeyAccumulator(Isolate* isolate, 34 KeyAccumulator(Isolate* isolate, PropertyFilter filter)
35 KeyFilter filter = KeyFilter::SKIP_SYMBOLS)
36 : isolate_(isolate), filter_(filter) {} 35 : isolate_(isolate), filter_(filter) {}
37 ~KeyAccumulator(); 36 ~KeyAccumulator();
38 37
39 bool AddKey(uint32_t key); 38 bool AddKey(uint32_t key);
40 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT); 39 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT);
41 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT); 40 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT);
42 void AddKeys(Handle<FixedArray> array, 41 void AddKeys(Handle<FixedArray> array,
43 AddKeyConversion convert = DO_NOT_CONVERT); 42 AddKeyConversion convert = DO_NOT_CONVERT);
44 void AddKeys(Handle<JSObject> array, 43 void AddKeys(Handle<JSObject> array,
45 AddKeyConversion convert = DO_NOT_CONVERT); 44 AddKeyConversion convert = DO_NOT_CONVERT);
46 void AddKeysFromProxy(Handle<JSObject> array); 45 void AddKeysFromProxy(Handle<JSObject> array);
47 bool AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys, 46 bool AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys);
48 KeyFilter filter, Enumerability enum_policy);
49 void AddElementKeysFromInterceptor(Handle<JSObject> array); 47 void AddElementKeysFromInterceptor(Handle<JSObject> array);
50 // Jump to the next level, pushing the current |levelLength_| to 48 // Jump to the next level, pushing the current |levelLength_| to
51 // |levelLengths_| and adding a new list to |elements_|. 49 // |levelLengths_| and adding a new list to |elements_|.
52 void NextPrototype(); 50 void NextPrototype();
53 // Sort the integer indices in the last list in |elements_| 51 // Sort the integer indices in the last list in |elements_|
54 void SortCurrentElementsList(); 52 void SortCurrentElementsList();
55 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); 53 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS);
56 int length() { return length_; } 54 int length() { return length_; }
57 Isolate* isolate() { return isolate_; } 55 Isolate* isolate() { return isolate_; }
58 56
59 private: 57 private:
60 bool AddIntegerKey(uint32_t key); 58 bool AddIntegerKey(uint32_t key);
61 bool AddStringKey(Handle<Object> key, AddKeyConversion convert); 59 bool AddStringKey(Handle<Object> key, AddKeyConversion convert);
62 bool AddSymbolKey(Handle<Object> array); 60 bool AddSymbolKey(Handle<Object> array);
63 void SortCurrentElementsListRemoveDuplicates(); 61 void SortCurrentElementsListRemoveDuplicates();
64 62
65 Isolate* isolate_; 63 Isolate* isolate_;
66 KeyFilter filter_; 64 PropertyFilter filter_;
67 // |elements_| contains the sorted element keys (indices) per level. 65 // |elements_| contains the sorted element keys (indices) per level.
68 std::vector<std::vector<uint32_t>*> elements_; 66 std::vector<std::vector<uint32_t>*> elements_;
69 // |protoLengths_| contains the total number of keys (elements + properties) 67 // |protoLengths_| contains the total number of keys (elements + properties)
70 // per level. Negative values mark counts for a level with keys from a proxy. 68 // per level. Negative values mark counts for a level with keys from a proxy.
71 std::vector<int> level_lengths_; 69 std::vector<int> level_lengths_;
72 // |string_properties_| contains the unique String property keys for all 70 // |string_properties_| contains the unique String property keys for all
73 // levels in insertion order per level. 71 // levels in insertion order per level.
74 Handle<OrderedHashSet> string_properties_; 72 Handle<OrderedHashSet> string_properties_;
75 // |symbol_properties_| contains the unique Symbol property keys for all 73 // |symbol_properties_| contains the unique Symbol property keys for all
76 // levels in insertion order per level. 74 // levels in insertion order per level.
77 Handle<OrderedHashSet> symbol_properties_; 75 Handle<OrderedHashSet> symbol_properties_;
78 // |length_| keeps track of the total number of all element and property keys. 76 // |length_| keeps track of the total number of all element and property keys.
79 int length_ = 0; 77 int length_ = 0;
80 // |levelLength_| keeps track of the number of String keys in the current 78 // |levelLength_| keeps track of the number of String keys in the current
81 // level. 79 // level.
82 int level_string_length_ = 0; 80 int level_string_length_ = 0;
83 // |levelSymbolLength_| keeps track of the number of Symbol keys in the 81 // |levelSymbolLength_| keeps track of the number of Symbol keys in the
84 // current level. 82 // current level.
85 int level_symbol_length_ = 0; 83 int level_symbol_length_ = 0;
86 84
87 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); 85 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator);
88 }; 86 };
89 87
90 88
91 } // namespace internal 89 } // namespace internal
92 } // namespace v8 90 } // namespace v8
93 91
94 92
95 #endif // V8_KEY_ACCUMULATOR_H_ 93 #endif // V8_KEY_ACCUMULATOR_H_
OLDNEW
« no previous file with comments | « src/json-stringifier.h ('k') | src/key-accumulator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698