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

Unified Diff: src/utils.h

Issue 15943002: v8 typed arrays: add DataView type (Closed)
Patch Set: v8 typed arrays: add DataView type, v2 Created 7 years, 7 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 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 b16730b8c46d750c1e264ad07713868c2b32d804..50af2597c7d00866f57da223a086f3acda35dddb 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -246,6 +246,46 @@ inline int StrLength(const char* string) {
}
+template <typename T>
+inline void Swizzle(T* value) {
+ char* start = reinterpret_cast<char*>(value);
+ char* end = start + sizeof(*value) - 1;
+ while (start < end) {
+ char t = *start;
+ *start++ = *end;
+ *end-- = t;
+ }
+}
+
+
+enum Endianness {
+ kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
+ kBigEndian
+};
+
+
+inline enum Endianness GetEndianness() {
Dmitry Lomov (no reviews) 2013/06/03 13:09:04 This belongs to cpu.h. Should be a #define with po
bnoordhuis 2013/06/03 13:48:12 I'll move it but is turning it into a macro necess
Dmitry Lomov (no reviews) 2013/06/03 14:42:49 Explicitly define expected endianness using V8_TAR
+ // Constant-folded by the compiler.
+ const union {
+ uint8_t u8[2];
+ uint16_t u16;
+ } u = {
+ { 1, 0 }
+ };
+ return u.u16 == 1 ? kLittleEndian : kBigEndian;
+}
+
+
+inline bool IsLittleEndian() {
+ return GetEndianness() == kLittleEndian;
+}
+
+
+inline bool IsBigEndian() {
+ return GetEndianness() == kBigEndian;
+}
+
+
// ----------------------------------------------------------------------------
// BitField is a help template for encoding and decode bitfield with
// unsigned content.

Powered by Google App Engine
This is Rietveld 408576698