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

Unified Diff: src/interpreter/bytecode-array-random-iterator.h

Issue 2536653003: [ignition] Rewrite reverse iterator as random iterator (Closed)
Patch Set: Rebase Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/bytecode-analysis.cc ('k') | src/interpreter/bytecode-array-random-iterator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-array-random-iterator.h
diff --git a/src/interpreter/bytecode-array-random-iterator.h b/src/interpreter/bytecode-array-random-iterator.h
new file mode 100644
index 0000000000000000000000000000000000000000..7d559ea1764a144664090e48fc1a8270f89d3f08
--- /dev/null
+++ b/src/interpreter/bytecode-array-random-iterator.h
@@ -0,0 +1,78 @@
+// 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 "src/interpreter/bytecode-array-accessor.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 BytecodeArrayAccessor {
+ public:
+ explicit BytecodeArrayRandomIterator(Handle<BytecodeArray> bytecode_array,
+ Zone* zone);
+
+ 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_; }
+
+ size_t size() const { return offsets_.size(); }
+
+ void GoToIndex(int index) {
+ current_index_ = index;
+ UpdateOffsetFromIndex();
+ }
+ void GoToStart() {
+ current_index_ = 0;
+ UpdateOffsetFromIndex();
+ }
+ void GoToEnd() {
+ DCHECK_LT(offsets_.size() - 1, static_cast<size_t>(INT_MAX));
+ current_index_ = static_cast<int>(offsets_.size() - 1);
+ UpdateOffsetFromIndex();
+ }
+
+ bool IsValid() const;
+
+ private:
+ ZoneVector<int> offsets_;
+ int current_index_;
+
+ void UpdateOffsetFromIndex();
+
+ DISALLOW_COPY_AND_ASSIGN(BytecodeArrayRandomIterator);
+};
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8
+
+#endif // V8_INTERPRETER_BYTECODE_ARRAY_RANDOM_ITERATOR_H_
« no previous file with comments | « src/compiler/bytecode-analysis.cc ('k') | src/interpreter/bytecode-array-random-iterator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698