diff options
author | jwd@chromium.org <jwd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-16 15:29:27 +0000 |
---|---|---|
committer | jwd@chromium.org <jwd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-16 15:29:27 +0000 |
commit | 7f8ce3d9311fd6233f993bef7a66fc7912dfd8d1 (patch) | |
tree | 97f51e085a194986dae2fbfab97f003f7bff2a65 /base/sys_byteorder.h | |
parent | ab675b683a15431e1f11aaf2f4de26a3fbb1dcc1 (diff) | |
download | chromium_src-7f8ce3d9311fd6233f993bef7a66fc7912dfd8d1.zip chromium_src-7f8ce3d9311fd6233f993bef7a66fc7912dfd8d1.tar.gz chromium_src-7f8ce3d9311fd6233f993bef7a66fc7912dfd8d1.tar.bz2 |
Fixing issues with alignment, undefined behaviour and endianness in the FieldTrial::HashName function. I also added new functions to base that convert from host order to little endian.
BUG=123230FieldTrialTest.HashName
TEST=FieldTrialTest.HashName
Review URL: http://codereview.chromium.org/10088001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132404 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sys_byteorder.h')
-rw-r--r-- | base/sys_byteorder.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/base/sys_byteorder.h b/base/sys_byteorder.h index 500999d..97e33ac 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 +} + // Converts the bytes in |x| from network to host order (endianness), and // returns the result. inline uint16 NetToHost16(uint16 x) { |