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

Side by Side Diff: src/vector.h

Issue 1204123003: Reland Extend big-disjunction optimization to case-independent regexps (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Skip slow architecture-independent tests on slower CPUs and simulators Created 5 years, 6 months 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 unified diff | Download patch
« no previous file with comments | « src/list-inl.h ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_VECTOR_H_ 5 #ifndef V8_VECTOR_H_
6 #define V8_VECTOR_H_ 6 #define V8_VECTOR_H_
7 7
8 #include <string.h> 8 #include <string.h>
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 inline iterator begin() const { return &start_[0]; } 62 inline iterator begin() const { return &start_[0]; }
63 inline iterator end() const { return &start_[length_]; } 63 inline iterator end() const { return &start_[length_]; }
64 64
65 // Returns a clone of this vector with a new backing store. 65 // Returns a clone of this vector with a new backing store.
66 Vector<T> Clone() const { 66 Vector<T> Clone() const {
67 T* result = NewArray<T>(length_); 67 T* result = NewArray<T>(length_);
68 for (int i = 0; i < length_; i++) result[i] = start_[i]; 68 for (int i = 0; i < length_; i++) result[i] = start_[i];
69 return Vector<T>(result, length_); 69 return Vector<T>(result, length_);
70 } 70 }
71 71
72 void Sort(int (*cmp)(const T*, const T*), size_t s, size_t l) { 72 template <typename CompareFunction>
73 std::sort(start() + s, start() + s + l, RawComparer(cmp)); 73 void Sort(CompareFunction cmp, size_t s, size_t l) {
74 std::sort(start() + s, start() + s + l, RawComparer<CompareFunction>(cmp));
74 } 75 }
75 76
76 void Sort(int (*cmp)(const T*, const T*)) { 77 template <typename CompareFunction>
77 std::sort(start(), start() + length(), RawComparer(cmp)); 78 void Sort(CompareFunction cmp) {
79 std::sort(start(), start() + length(), RawComparer<CompareFunction>(cmp));
78 } 80 }
79 81
80 void Sort() { 82 void Sort() {
81 std::sort(start(), start() + length()); 83 std::sort(start(), start() + length());
82 } 84 }
83 85
84 void StableSort(int (*cmp)(const T*, const T*), size_t s, size_t l) { 86 template <typename CompareFunction>
85 std::stable_sort(start() + s, start() + s + l, RawComparer(cmp)); 87 void StableSort(CompareFunction cmp, size_t s, size_t l) {
88 std::stable_sort(start() + s, start() + s + l,
89 RawComparer<CompareFunction>(cmp));
86 } 90 }
87 91
88 void StableSort(int (*cmp)(const T*, const T*)) { 92 template <typename CompareFunction>
89 std::stable_sort(start(), start() + length(), RawComparer(cmp)); 93 void StableSort(CompareFunction cmp) {
94 std::stable_sort(start(), start() + length(),
95 RawComparer<CompareFunction>(cmp));
90 } 96 }
91 97
92 void StableSort() { std::stable_sort(start(), start() + length()); } 98 void StableSort() { std::stable_sort(start(), start() + length()); }
93 99
94 void Truncate(int length) { 100 void Truncate(int length) {
95 DCHECK(length <= length_); 101 DCHECK(length <= length_);
96 length_ = length; 102 length_ = length;
97 } 103 }
98 104
99 // Releases the array underlying this vector. Once disposed the 105 // Releases the array underlying this vector. Once disposed the
(...skipping 29 matching lines...) Expand all
129 return true; 135 return true;
130 } 136 }
131 137
132 protected: 138 protected:
133 void set_start(T* start) { start_ = start; } 139 void set_start(T* start) { start_ = start; }
134 140
135 private: 141 private:
136 T* start_; 142 T* start_;
137 int length_; 143 int length_;
138 144
145 template <typename CookedComparer>
139 class RawComparer { 146 class RawComparer {
140 public: 147 public:
141 explicit RawComparer(int (*cmp)(const T*, const T*)) : cmp_(cmp) {} 148 explicit RawComparer(CookedComparer cmp) : cmp_(cmp) {}
142 bool operator()(const T& a, const T& b) { 149 bool operator()(const T& a, const T& b) {
143 return cmp_(&a, &b) < 0; 150 return cmp_(&a, &b) < 0;
144 } 151 }
145 152
146 private: 153 private:
147 int (*cmp_)(const T*, const T*); 154 CookedComparer cmp_;
148 }; 155 };
149 }; 156 };
150 157
151 158
152 template <typename T> 159 template <typename T>
153 class ScopedVector : public Vector<T> { 160 class ScopedVector : public Vector<T> {
154 public: 161 public:
155 explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length), length) { } 162 explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length), length) { }
156 ~ScopedVector() { 163 ~ScopedVector() {
157 DeleteArray(this->start()); 164 DeleteArray(this->start());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 198
192 inline Vector<char> MutableCStrVector(char* data, int max) { 199 inline Vector<char> MutableCStrVector(char* data, int max) {
193 int length = StrLength(data); 200 int length = StrLength(data);
194 return Vector<char>(data, (length < max) ? length : max); 201 return Vector<char>(data, (length < max) ? length : max);
195 } 202 }
196 203
197 204
198 } } // namespace v8::internal 205 } } // namespace v8::internal
199 206
200 #endif // V8_VECTOR_H_ 207 #endif // V8_VECTOR_H_
OLDNEW
« no previous file with comments | « src/list-inl.h ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698