mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 20:30:00 +00:00
Pulled out EndianSwap into its own function.
Change-Id: I4a587102db8c435b739c92b6c464c94c4ea1fe42
This commit is contained in:
@@ -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) {
|
|||||||
#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) {
|
|||||||
#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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user