diff options
Diffstat (limited to 'deps/v8/src/vector.h')
-rw-r--r-- | deps/v8/src/vector.h | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/deps/v8/src/vector.h b/deps/v8/src/vector.h index 03e5d6cb1e..7ae4f0eb04 100644 --- a/deps/v8/src/vector.h +++ b/deps/v8/src/vector.h @@ -20,8 +20,9 @@ template <typename T> class Vector { public: Vector() : start_(NULL), length_(0) {} - Vector(T* data, int length) : start_(data), length_(length) { - DCHECK(length == 0 || (length > 0 && data != NULL)); + + Vector(T* data, size_t length) : start_(data), length_(length) { + DCHECK(length == 0 || data != NULL); } template <int N> @@ -33,15 +34,20 @@ class Vector { // Returns a vector using the same backing storage as this one, // spanning from and including 'from', to but not including 'to'. - Vector<T> SubVector(int from, int to) const { - DCHECK(0 <= from); - SLOW_DCHECK(from <= to); - SLOW_DCHECK(static_cast<unsigned>(to) <= static_cast<unsigned>(length_)); + Vector<T> SubVector(size_t from, size_t to) const { + DCHECK_LE(from, to); + DCHECK_LE(to, length_); return Vector<T>(start() + from, to - from); } // Returns the length of the vector. - int length() const { return length_; } + int length() const { + DCHECK(length_ <= static_cast<size_t>(std::numeric_limits<int>::max())); + return static_cast<int>(length_); + } + + // Returns the length of the vector as a size_t. + size_t size() const { return length_; } // Returns whether or not the vector is empty. bool is_empty() const { return length_ == 0; } @@ -50,13 +56,12 @@ class Vector { T* start() const { return start_; } // Access individual vector elements - checks bounds in debug mode. - T& operator[](int index) const { - DCHECK_LE(0, index); + T& operator[](size_t index) const { DCHECK_LT(index, length_); return start_[index]; } - const T& at(int index) const { return operator[](index); } + const T& at(size_t index) const { return operator[](index); } T& first() { return start_[0]; } @@ -69,7 +74,7 @@ class Vector { // Returns a clone of this vector with a new backing store. Vector<T> Clone() const { T* result = NewArray<T>(length_); - for (int i = 0; i < length_; i++) result[i] = start_[i]; + for (size_t i = 0; i < length_; i++) result[i] = start_[i]; return Vector<T>(result, length_); } @@ -101,7 +106,7 @@ class Vector { void StableSort() { std::stable_sort(start(), start() + length()); } - void Truncate(int length) { + void Truncate(size_t length) { DCHECK(length <= length_); length_ = length; } @@ -114,8 +119,8 @@ class Vector { length_ = 0; } - inline Vector<T> operator+(int offset) { - DCHECK(offset < length_); + inline Vector<T> operator+(size_t offset) { + DCHECK_LT(offset, length_); return Vector<T>(start_ + offset, length_ - offset); } @@ -134,7 +139,7 @@ class Vector { bool operator==(const Vector<T>& other) const { if (length_ != other.length_) return false; if (start_ == other.start_) return true; - for (int i = 0; i < length_; ++i) { + for (size_t i = 0; i < length_; ++i) { if (start_[i] != other.start_[i]) { return false; } @@ -147,7 +152,7 @@ class Vector { private: T* start_; - int length_; + size_t length_; template <typename CookedComparer> class RawComparer { |