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

Unified Diff: base/sys_byteorder.h

Issue 10088001: Fixing issues with alignment, undefined behaviour and endianness in the FieldTrial::HashName functi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« no previous file with comments | « base/metrics/field_trial.cc ('k') | no next file » | 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 500999d6423e7fd4a1d369301f550c954359841a..97e33acfdab33d5093cf5441284eb5f25a314c2b 100644
--- a/base/sys_byteorder.h
+++ b/base/sys_byteorder.h
@@ -69,6 +69,30 @@ inline uint64 ByteSwap(uint64 x) {
#endif
}
+// Converts the bytes in |x| from host order (endianness) to little endian, and
+// returns the result.
+inline uint16 ByteSwapToLE16(uint16 x) {
+#if defined(ARCH_CPU_LITTLE_ENDIAN)
+ return x;
+#else
+ return ByteSwap(x);
+#endif
+}
+inline uint32 ByteSwapToLE32(uint32 x) {
+#if defined(ARCH_CPU_LITTLE_ENDIAN)
+ return x;
+#else
+ return ByteSwap(x);
+#endif
+}
+inline uint64 ByteSwapToLE64(uint64 x) {
+#if defined(ARCH_CPU_LITTLE_ENDIAN)
+ return x;
+#else
+ return ByteSwap(x);
+#endif
Ilya Sherman 2012/04/13 20:19:20 Hmm, why are you adding these functions rather tha
jwd 2012/04/13 20:33:44 We decided that we wanted the values in little-end
Ilya Sherman 2012/04/13 21:27:33 Ok, fair enough. Thanks :)
+}
+
// Converts the bytes in |x| from network to host order (endianness), and
// returns the result.
inline uint16 NetToHost16(uint16 x) {
« no previous file with comments | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698