From ddce90870c1e7bc6dc74ea65077001cfd987b68d Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 26 Jan 2016 23:18:09 -0800 Subject: [PATCH] Extract endianness checks into Portability.h Summary: [Folly] Extract endianness checks into Portability.h. Reviewed By: fugalh Differential Revision: D2857924 fb-gh-sync-id: 23ecd2a3cad661024acb62769cd85df394786c59 --- folly/FBString.h | 7 ------- folly/Portability.h | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/folly/FBString.h b/folly/FBString.h index d26b961d..2acaaf79 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -289,13 +289,6 @@ private: * to extract capacity/category. */ template class fbstring_core { -protected: - static constexpr bool kIsLittleEndian = - __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__; - static constexpr bool kIsBigEndian = - __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__; - static_assert( - kIsLittleEndian || kIsBigEndian, "unable to identify endianness"); public: fbstring_core() noexcept { reset(); } diff --git a/folly/Portability.h b/folly/Portability.h index 63318a2c..9784ef2e 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -305,6 +305,21 @@ typedef SSIZE_T ssize_t; #endif +// Endianness +namespace folly { +#ifdef _MSC_VER +// It's MSVC, so we just have to guess ... and allow an override +#ifdef FOLLY_ENDIAN_BE +constexpr auto kIsLittleEndian = false; +#else +constexpr auto kIsLittleEndian = true; +#endif +#else +constexpr auto kIsLittleEndian = __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__; +#endif +constexpr auto kIsBigEndian = !kIsLittleEndian; +} + #ifndef FOLLY_SSE # if defined(__SSE4_2__) # define FOLLY_SSE 4 -- 2.34.1