blob: ce3014e6b6761fec4d7b259c1149b36a0c2ecc72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_INTERPRETER_BYTECODE_ARRAY_RANDOM_ITERATOR_H_
#define V8_INTERPRETER_BYTECODE_ARRAY_RANDOM_ITERATOR_H_
#include <memory>
#include "src/interpreter/bytecode-array-iterator.h"
#include "src/zone/zone-containers.h"
#include "src/zone/zone.h"
namespace v8 {
namespace internal {
namespace interpreter {
class V8_EXPORT_PRIVATE BytecodeArrayRandomIterator final
: public BytecodeArrayIterator {
public:
BytecodeArrayRandomIterator(Handle<BytecodeArray> bytecode_array, Zone* zone);
BytecodeArrayRandomIterator(const BytecodeArrayRandomIterator&) = delete;
BytecodeArrayRandomIterator& operator=(const BytecodeArrayRandomIterator&) =
delete;
BytecodeArrayRandomIterator& operator++() {
++current_index_;
UpdateOffsetFromIndex();
return *this;
}
BytecodeArrayRandomIterator& operator--() {
--current_index_;
UpdateOffsetFromIndex();
return *this;
}
BytecodeArrayRandomIterator& operator+=(int offset) {
current_index_ += offset;
UpdateOffsetFromIndex();
return *this;
}
BytecodeArrayRandomIterator& operator-=(int offset) {
current_index_ -= offset;
UpdateOffsetFromIndex();
return *this;
}
int current_index() const { return current_index_; }
int size() const { return static_cast<int>(offsets_.size()); }
void GoToIndex(int index) {
current_index_ = index;
UpdateOffsetFromIndex();
}
void GoToStart() {
current_index_ = 0;
UpdateOffsetFromIndex();
}
void GoToEnd() {
current_index_ = size() - 1;
UpdateOffsetFromIndex();
}
bool IsValid() const;
private:
ZoneVector<int> offsets_;
int current_index_;
void Initialize();
void UpdateOffsetFromIndex();
};
} // namespace interpreter
} // namespace internal
} // namespace v8
#endif // V8_INTERPRETER_BYTECODE_ARRAY_RANDOM_ITERATOR_H_
|