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

Unified Diff: src/utils.h

Issue 12427: Merge regexp2000 back into bleeding_edge (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
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
===================================================================
--- src/utils.h (revision 830)
+++ src/utils.h (working copy)
@@ -83,6 +83,23 @@
}
+template <typename T>
+static int Spaceship(const T& a, const T& b) {
iposva 2008/11/26 06:56:22 Comments please. What kind of spaceship is this? T
Christian Plesner Hansen 2008/11/26 07:49:51 I'll rename it. The name "spaceship" is apparentl
+ 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);
@@ -283,6 +300,15 @@
return Vector<T>(NewArray<T>(length), length);
}
+ // 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) {
+ ASSERT(from < length_);
+ ASSERT(to <= length_);
+ ASSERT(from < to);
+ return Vector<T>(start() + from, to - from);
+ }
+
// Returns the length of the vector.
int length() const { return length_; }
@@ -298,6 +324,10 @@
return start_[index];
}
+ T& first() { return start_[0]; }
+
+ T& last() { return start_[length_ - 1]; }
+
// Returns a clone of this vector with a new backing store.
Vector<T> Clone() const {
T* result = NewArray<T>(length_);
@@ -305,6 +335,18 @@
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() {
@@ -465,6 +507,58 @@
}
}
+
+static inline int Load16(const byte* pc) {
iposva 2008/11/26 06:56:22 I understand that this is most likely used when ac
Erik Corry 2008/11/26 12:18:36 Yes, that's what it's used for and in this context
+#ifdef CAN_READ_UNALIGNED
+ return *reinterpret_cast<const uint16_t*>(pc);
+#else
+ uint32_t word;
+ word = pc[1];
+ word |= pc[0] << 8;
+ return word;
+#endif
+}
+
+
+static inline int Load32(const byte* pc) {
+#ifdef CAN_READ_UNALIGNED
+ return *reinterpret_cast<const uint32_t*>(pc);
+#else
+ uint32_t word;
+ word = pc[3];
+ word |= pc[2] << 8;
+ word |= pc[1] << 16;
+ word |= pc[0] << 24;
+ return word;
+#endif
+}
+
+
+static inline void Store16(byte* pc, uint16_t value) {
+#ifdef CAN_READ_UNALIGNED
+ *reinterpret_cast<uint16_t*>(pc) = value;
+#else
+ pc[1] = value;
+ pc[0] = value >> 8;
+#endif
+}
+
+
+static inline void Store32(byte* pc, uint32_t value) {
+#ifdef CAN_READ_UNALIGNED
+ *reinterpret_cast<uint32_t*>(pc) = value;
+#else
+ pc[3] = value;
+ pc[2] = value >> 8;
+ pc[1] = value >> 16;
+ pc[0] = value >> 24;
+#endif
+}
+
+
+
+
+
} } // namespace v8::internal
#endif // V8_UTILS_H_

Powered by Google App Engine
This is Rietveld 408576698