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

Unified Diff: src/utils.h

Issue 10682: Inverted character classes (Closed)
Patch Set: Created 12 years, 1 month 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
Index: src/utils.h
diff --git a/src/utils.h b/src/utils.h
index be8d0a7698a792b513c9f590dddeb6e9406fd475..e3e000fcf28f3c2c17a281c9601ab8fae73e316c 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -83,6 +83,23 @@ static inline T RoundUp(T x, int m) {
}
+template <typename T>
+static int Spaceship(const T& a, const T& b) {
Erik Corry 2008/11/13 11:45:43 The reasoning behind this name is a little opaque
Christian Plesner Hansen 2008/11/13 11:58:37 http://en.wikipedia.org/wiki/Spaceship_operator W
+ if (a == b)
+ return 0;
+ else if (a < b)
+ return -1;
+ else
+ return 1;
+}
+
+
+template <typename T>
+static int PointerSpaceship(const T* a, const T* b) {
+ return Spaceship<T>(*a, *b);
+}
+
+
// Returns the smallest power of two which is >= x. If you pass in a
// number that is already a power of two, it is returned as is.
uint32_t RoundUpToPowerOf2(uint32_t x);
@@ -318,6 +335,18 @@ class Vector {
return Vector<T>(result, length_);
}
+ void Sort(int (*cmp)(const T*, const T*)) {
+ typedef int (*RawComparer)(const void*, const void*);
+ qsort(start(),
+ length(),
+ sizeof(T),
+ reinterpret_cast<RawComparer>(cmp));
+ }
+
+ void Sort() {
+ Sort(PointerSpaceship<T>);
+ }
+
// Releases the array underlying this vector. Once disposed the
// vector is empty.
void Dispose() {
« src/jsregexp.cc ('K') | « src/list-inl.h ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698