Extract endianness checks into Portability.h
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 27 Jan 2016 07:18:09 +0000 (23:18 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Wed, 27 Jan 2016 08:20:21 +0000 (00:20 -0800)
Summary: [Folly] Extract endianness checks into Portability.h.

Reviewed By: fugalh

Differential Revision: D2857924

fb-gh-sync-id: 23ecd2a3cad661024acb62769cd85df394786c59

folly/FBString.h
folly/Portability.h

index d26b961d2a2bc325334885a7044ecb4fb28b98a7..2acaaf79bf5b924e5ec28958e8eec33459e14bb1 100644 (file)
@@ -289,13 +289,6 @@ private:
  * to extract capacity/category.
  */
 template <class Char> 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(); }
 
index 63318a2ce3a2ae14783dc5f265071760b1756bd5..9784ef2e9faf4da22d7e46a68063f61f92d7f1e6 100644 (file)
@@ -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