Line data Source code
1 : // Copyright 2015 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 : #include "src/interpreter/bytecode-array-random-iterator.h"
6 : #include "src/objects-inl.h"
7 :
8 : namespace v8 {
9 : namespace internal {
10 : namespace interpreter {
11 :
12 430882 : BytecodeArrayRandomIterator::BytecodeArrayRandomIterator(
13 : Handle<BytecodeArray> bytecode_array, Zone* zone)
14 29520672 : : BytecodeArrayAccessor(bytecode_array, 0), offsets_(zone) {
15 : // Run forwards through the bytecode array to determine the offset of each
16 : // bytecode.
17 14760336 : while (current_offset() < bytecode_array->length()) {
18 28658908 : offsets_.push_back(current_offset());
19 14329454 : SetOffset(current_offset() + current_bytecode_size());
20 : }
21 : GoToStart();
22 430882 : }
23 :
24 14760187 : bool BytecodeArrayRandomIterator::IsValid() const {
25 63776765 : return current_index_ >= 0 &&
26 46217693 : static_cast<size_t>(current_index_) < offsets_.size();
27 : }
28 :
29 17559072 : void BytecodeArrayRandomIterator::UpdateOffsetFromIndex() {
30 17559072 : if (IsValid()) {
31 34256388 : SetOffset(offsets_[current_index_]);
32 : }
33 17559065 : }
34 :
35 : } // namespace interpreter
36 : } // namespace internal
37 : } // namespace v8
|