OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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_INTERPRETER_BYTECODE_ARRAY_REVERSE_ITERATOR_H_ | |
6 #define V8_INTERPRETER_BYTECODE_ARRAY_REVERSE_ITERATOR_H_ | |
7 | |
8 #include "src/interpreter/bytecode-array-accessor.h" | |
9 #include "src/zone/zone-containers.h" | |
10 #include "src/zone/zone.h" | |
11 | |
12 namespace v8 { | |
13 namespace internal { | |
14 namespace interpreter { | |
15 | |
16 class V8_EXPORT_PRIVATE BytecodeArrayRandomIterator final | |
17 : public BytecodeArrayAccessor { | |
18 public: | |
19 explicit BytecodeArrayRandomIterator(Handle<BytecodeArray> bytecode_array, | |
20 Zone* zone); | |
21 | |
22 BytecodeArrayRandomIterator& operator++() { | |
23 ++current_index_; | |
24 UpdateOffsetFromIndex(); | |
25 return *this; | |
26 } | |
27 BytecodeArrayRandomIterator& operator--() { | |
28 --current_index_; | |
29 UpdateOffsetFromIndex(); | |
30 return *this; | |
31 } | |
32 | |
33 BytecodeArrayRandomIterator& operator+=(int offset) { | |
34 current_index_ += offset; | |
35 UpdateOffsetFromIndex(); | |
36 return *this; | |
37 } | |
38 | |
39 int current_index() const { return current_index_; } | |
40 | |
41 size_t size() const { return offsets_.size(); } | |
42 | |
43 void GoToIndex(int index) { | |
44 current_index_ = index; | |
45 UpdateOffsetFromIndex(); | |
46 } | |
47 void GoToStart() { | |
48 current_index_ = 0; | |
49 UpdateOffsetFromIndex(); | |
50 } | |
51 void GoToEnd() { | |
52 DCHECK_LT(offsets_.size() - 1, static_cast<size_t>(INT_MAX)); | |
53 current_index_ = static_cast<int>(offsets_.size() - 1); | |
54 UpdateOffsetFromIndex(); | |
55 } | |
56 | |
57 bool Valid() const; | |
rmcilroy
2016/11/29 12:09:32
nit IsValid
Leszek Swirski
2016/11/29 15:05:35
Done.
| |
58 | |
59 private: | |
60 ZoneVector<int> offsets_; | |
61 int current_index_; | |
62 | |
63 void UpdateOffsetFromIndex(); | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayRandomIterator); | |
66 }; | |
67 | |
68 } // namespace interpreter | |
69 } // namespace internal | |
70 } // namespace v8 | |
71 | |
72 #endif // V8_INTERPRETER_BYTECODE_ARRAY_REVERSE_ITERATOR_H_ | |
OLD | NEW |