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

Unified Diff: base/sys_byteorder.h

Issue 2518253002: Move Partition Allocator into Chromium base. (Closed)
Patch Set: Add static_asserts to ensure that ByteSwapUintPtrT is correct, and just use CHECK. Created 4 years 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
« no previous file with comments | « base/logging.cc ('k') | base/sys_byteorder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_byteorder.h
diff --git a/base/sys_byteorder.h b/base/sys_byteorder.h
index 8d9066c70228bfd7c36ec0cb3a2afe30dc006a2d..051f3e22c7cf696ba14d4b1a184b36fb20e681c3 100644
--- a/base/sys_byteorder.h
+++ b/base/sys_byteorder.h
@@ -46,6 +46,20 @@ inline uint64_t ByteSwap(uint64_t x) {
#endif
}
+inline uintptr_t ByteSwapUintPtrT(uintptr_t x) {
+#if defined(ARCH_CPU_64_BITS)
+ static_assert(sizeof(uint64_t) == sizeof(uintptr_t),
+ "uintptr_t not the same as uint64_t");
+ return ByteSwap(static_cast<uint64_t>(x));
+#elif defined(ARCH_CPU_32_BITS)
+ static_assert(sizeof(uint32_t) == sizeof(uintptr_t),
+ "uintptr_t not the same as uinti32_t");
gab 2016/12/09 21:01:56 nit: typo s/uinti32_t/uint32_t/
+ return ByteSwap(static_cast<uint32_t>(x));
+#else
+#error architecture not supported
+#endif
+}
+
// Converts the bytes in |x| from host order (endianness) to little endian, and
// returns the result.
inline uint16_t ByteSwapToLE16(uint16_t x) {
« no previous file with comments | « base/logging.cc ('k') | base/sys_byteorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698