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

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

Issue 1425403002: [runtime] Support Symbols in KeyAccumulator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: adressing nits + adding separate file for KeyAccumulator Created 5 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef V8_KEY_ACCUMULATOR_H_
6 #define V8_KEY_ACCUMULATOR_H_
7
8 #include "src/isolate.h"
9 #include "src/objects.h"
10
11 namespace v8 {
12 namespace internal {
13
14 enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC };
15
16 // This is a helper class for JSReceiver::GetKeys which collects and sorts keys.
17 // GetKeys needs to sort keys per prototype level, first showing the integer
18 // indices from elements then the strings from the properties. However, this
19 // does not apply to proxies which are in full control of how the keys are
20 // sorted.
21 //
22 // For performance reasons the KeyAccumulator internally separates integer
23 // keys in |elements_| into sorted lists per prototype level. String keys are
24 // collected in |properties_|, a single OrderedHashSet. To separate the keys per
25 // level later when assembling the final list, |levelLengths_| keeps track of
26 // the total number of keys (integers + strings) per level.
27 //
neis 2015/11/04 12:49:27 Can you update the comment to say something about
Camillo Bruni 2015/11/04 13:09:30 yes, missed that.
28 // Only unique keys are kept by the KeyAccumulator, strings are stored in a
29 // HashSet for inexpensive lookups. Integer keys are kept in sorted lists which
30 // are more compact and allow for reasonably fast includes check.
31 class KeyAccumulator final BASE_EMBEDDED {
32 public:
33 explicit KeyAccumulator(Isolate* isolate,
34 KeyFilter filter = KeyFilter::SKIP_SYMBOLS)
35 : isolate_(isolate), filter_(filter) {}
36 ~KeyAccumulator();
37
38 bool AddKey(uint32_t key);
39 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT);
40 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT);
41 void AddKeys(Handle<FixedArray> array,
42 AddKeyConversion convert = DO_NOT_CONVERT);
43 void AddKeys(Handle<JSObject> array,
44 AddKeyConversion convert = DO_NOT_CONVERT);
45 void AddKeysFromProxy(Handle<JSObject> array);
46 void AddElementKeysFromInterceptor(Handle<JSObject> array);
47 // Jump to the next level, pushing the current |levelLength_| to
48 // |levelLengths_| and adding a new list to |elements_|.
49 void NextPrototype();
50 // Sort the integer indices in the last list in |elements_|
51 void SortCurrentElementsList();
52 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS);
53 int length() { return length_; }
54
55 private:
56 bool AddStringKey(Handle<Object> key, AddKeyConversion convert);
57 bool AddSymbolKey(Handle<Object> array);
58 void SortCurrentElementsListRemoveDuplicates();
59
60 Isolate* isolate_;
61 KeyFilter filter_;
62 // |elements_| contains the sorted element keys (indices) per level.
63 std::vector<std::vector<uint32_t>*> elements_;
64 // |protoLengths_| contains the total number of keys (elements + properties)
65 // per level. Negative values mark counts for a level with keys from a proxy.
66 std::vector<int> level_lengths_;
67 // |properties_| contains the property keys per level in insertion order.
68 Handle<OrderedHashSet> string_properties_;
69 // |properties_| contains the symbol property keys per level in
70 // insertion order.
neis 2015/11/04 12:49:27 Some variable names in the comments are wrong.
71 Handle<OrderedHashSet> symbol_properties_;
72 // |length_| keeps track of the total number of all element and property keys.
73 int length_ = 0;
74 // |levelLength_| keeps track of the total number of keys
75 // (elements + properties) in the current level.
neis 2015/11/04 12:49:27 These comments need to be updated too.
76 int level_string_length_ = 0;
77 // |levelSymbolLength_| keeps track of the total number of symbol keys
78 // (elements + properties) in the current level.
79 int level_symbol_length_ = 0;
80
81 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator);
82 };
83
84
85 } // namespace internal
86 } // namespace v8
87
88
89 #endif // V8_KEY_ACCUMULATOR_H_
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/key-accumulator.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698