Pulled out EndianSwap into its own function.

Change-Id: I4a587102db8c435b739c92b6c464c94c4ea1fe42
parent 1bba4fd9
...@@ -151,10 +151,7 @@ inline void EndianCheck() { ...@@ -151,10 +151,7 @@ inline void EndianCheck() {
(void)endiantest; (void)endiantest;
} }
template<typename T> T EndianScalar(T t) { template<typename T> T EndianSwap(T t) {
#if FLATBUFFERS_LITTLEENDIAN
return t;
#else
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma push_macro("__builtin_bswap16") #pragma push_macro("__builtin_bswap16")
#pragma push_macro("__builtin_bswap32") #pragma push_macro("__builtin_bswap32")
...@@ -163,8 +160,6 @@ template<typename T> T EndianScalar(T t) { ...@@ -163,8 +160,6 @@ template<typename T> T EndianScalar(T t) {
#define __builtin_bswap32 _byteswap_ulong #define __builtin_bswap32 _byteswap_ulong
#define __builtin_bswap64 _byteswap_uint64 #define __builtin_bswap64 _byteswap_uint64
#endif #endif
// If you're on the few remaining big endian platforms, we make the bold
// assumption you're also on gcc/clang, and thus have bswap intrinsics:
if (sizeof(T) == 1) { // Compile-time if-then's. if (sizeof(T) == 1) { // Compile-time if-then's.
return t; return t;
} else if (sizeof(T) == 2) { } else if (sizeof(T) == 2) {
...@@ -184,6 +179,13 @@ template<typename T> T EndianScalar(T t) { ...@@ -184,6 +179,13 @@ template<typename T> T EndianScalar(T t) {
#pragma pop_macro("__builtin_bswap32") #pragma pop_macro("__builtin_bswap32")
#pragma pop_macro("__builtin_bswap64") #pragma pop_macro("__builtin_bswap64")
#endif #endif
}
template<typename T> T EndianScalar(T t) {
#if FLATBUFFERS_LITTLEENDIAN
return t;
#else
return EndianSwap(t);
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment