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

Side by Side Diff: src/vector.h

Issue 1204013003: Revert of Extend big-disjunction optimization to case-independent regexps (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/regexp-sort.js » ('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 template <typename CompareFunction> 72 void Sort(int (*cmp)(const T*, const T*), size_t s, size_t l) {
73 void Sort(CompareFunction cmp, size_t s, size_t l) { 73 std::sort(start() + s, start() + s + l, RawComparer(cmp));
74 std::sort(start() + s, start() + s + l, RawComparer<CompareFunction>(cmp));
75 } 74 }
76 75
77 template <typename CompareFunction> 76 void Sort(int (*cmp)(const T*, const T*)) {
78 void Sort(CompareFunction cmp) { 77 std::sort(start(), start() + length(), RawComparer(cmp));
79 std::sort(start(), start() + length(), RawComparer<CompareFunction>(cmp));
80 } 78 }
81 79
82 void Sort() { 80 void Sort() {
83 std::sort(start(), start() + length()); 81 std::sort(start(), start() + length());
84 } 82 }
85 83
86 template <typename CompareFunction> 84 void StableSort(int (*cmp)(const T*, const T*), size_t s, size_t l) {
87 void StableSort(CompareFunction cmp, size_t s, size_t l) { 85 std::stable_sort(start() + s, start() + s + l, RawComparer(cmp));
88 std::stable_sort(start() + s, start() + s + l,
89 RawComparer<CompareFunction>(cmp));
90 } 86 }
91 87
92 template <typename CompareFunction> 88 void StableSort(int (*cmp)(const T*, const T*)) {
93 void StableSort(CompareFunction cmp) { 89 std::stable_sort(start(), start() + length(), RawComparer(cmp));
94 std::stable_sort(start(), start() + length(),
95 RawComparer<CompareFunction>(cmp));
96 } 90 }
97 91
98 void StableSort() { std::stable_sort(start(), start() + length()); } 92 void StableSort() { std::stable_sort(start(), start() + length()); }
99 93
100 void Truncate(int length) { 94 void Truncate(int length) {
101 DCHECK(length <= length_); 95 DCHECK(length <= length_);
102 length_ = length; 96 length_ = length;
103 } 97 }
104 98
105 // Releases the array underlying this vector. Once disposed the 99 // Releases the array underlying this vector. Once disposed the
(...skipping 29 matching lines...) Expand all
135 return true; 129 return true;
136 } 130 }
137 131
138 protected: 132 protected:
139 void set_start(T* start) { start_ = start; } 133 void set_start(T* start) { start_ = start; }
140 134
141 private: 135 private:
142 T* start_; 136 T* start_;
143 int length_; 137 int length_;
144 138
145 template <typename CookedComparer>
146 class RawComparer { 139 class RawComparer {
147 public: 140 public:
148 explicit RawComparer(CookedComparer cmp) : cmp_(cmp) {} 141 explicit RawComparer(int (*cmp)(const T*, const T*)) : cmp_(cmp) {}
149 bool operator()(const T& a, const T& b) { 142 bool operator()(const T& a, const T& b) {
150 return cmp_(&a, &b) < 0; 143 return cmp_(&a, &b) < 0;
151 } 144 }
152 145
153 private: 146 private:
154 CookedComparer cmp_; 147 int (*cmp_)(const T*, const T*);
155 }; 148 };
156 }; 149 };
157 150
158 151
159 template <typename T> 152 template <typename T>
160 class ScopedVector : public Vector<T> { 153 class ScopedVector : public Vector<T> {
161 public: 154 public:
162 explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length), length) { } 155 explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length), length) { }
163 ~ScopedVector() { 156 ~ScopedVector() {
164 DeleteArray(this->start()); 157 DeleteArray(this->start());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 191
199 inline Vector<char> MutableCStrVector(char* data, int max) { 192 inline Vector<char> MutableCStrVector(char* data, int max) {
200 int length = StrLength(data); 193 int length = StrLength(data);
201 return Vector<char>(data, (length < max) ? length : max); 194 return Vector<char>(data, (length < max) ? length : max);
202 } 195 }
203 196
204 197
205 } } // namespace v8::internal 198 } } // namespace v8::internal
206 199
207 #endif // V8_VECTOR_H_ 200 #endif // V8_VECTOR_H_
OLDNEW
« no previous file with comments | « src/list-inl.h ('k') | test/mjsunit/regexp-sort.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698