From 076e845912c2ac09cfb86d59bd1fdff350a40c39 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 3 Aug 2015 13:08:58 +0900 Subject: [PATCH] Run-time check for integer byte order rather than CMake check. It will easily be optimized out. --- ConfigureChecks.cmake | 11 ----------- config.h.cmake | 4 ---- taglib/toolkit/tbytevector.cpp | 4 ++-- taglib/toolkit/tstring.cpp | 2 +- taglib/toolkit/tutils.h | 21 +++------------------ 5 files changed, 6 insertions(+), 36 deletions(-) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index fad3ad34..08ef6a4d 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -1,7 +1,6 @@ include(CheckLibraryExists) include(CheckTypeSize) include(CheckCXXSourceCompiles) -include(TestBigEndian) # Check if the size of numeric types are suitable. @@ -35,16 +34,6 @@ if(NOT ${SIZEOF_DOUBLE} EQUAL 8) message(FATAL_ERROR "TagLib requires that double is 64-bit wide.") endif() -# Determine the CPU byte order. - -test_big_endian(IS_BIG_ENDIAN) - -if(NOT IS_BIG_ENDIAN) - set(SYSTEM_BYTEORDER 1) -else() - set(SYSTEM_BYTEORDER 2) -endif() - # Determine which kind of atomic operations your compiler supports. check_cxx_source_compiles(" diff --git a/config.h.cmake b/config.h.cmake index 2feded0f..a001c5c8 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -1,9 +1,5 @@ /* config.h. Generated by cmake from config.h.cmake */ -/* Integer byte order of your target system */ -/* 1 if little-endian, 2 if big-endian. */ -#cmakedefine SYSTEM_BYTEORDER ${SYSTEM_BYTEORDER} - /* Defined if your compiler supports some byte swap functions */ #cmakedefine HAVE_GCC_BYTESWAP_16 1 #cmakedefine HAVE_GCC_BYTESWAP_32 1 diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index ca1c30bc..6262bec6 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -209,7 +209,7 @@ T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignifica template T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst) { - static const bool isBigEndian = (Utils::SystemByteOrder == Utils::BigEndian); + const bool isBigEndian = (Utils::systemByteOrder() == Utils::BigEndian); const bool swap = (mostSignificantByteFirst != isBigEndian); if(offset + sizeof(T) > v.size()) @@ -228,7 +228,7 @@ T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst) template ByteVector fromNumber(T value, bool mostSignificantByteFirst) { - static const bool isBigEndian = (Utils::SystemByteOrder == Utils::BigEndian); + const bool isBigEndian = (Utils::systemByteOrder() == Utils::BigEndian); const bool swap = (mostSignificantByteFirst != isBigEndian); if(swap) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 15db518d..258e1fcf 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -828,7 +828,7 @@ void String::copyFromUTF16(const char *s, size_t length, Type t) } const String::Type String::WCharByteOrder - = (Utils::SystemByteOrder == Utils::BigEndian) ? String::UTF16BE : String::UTF16LE; + = (Utils::systemByteOrder() == Utils::BigEndian) ? String::UTF16BE : String::UTF16LE; } diff --git a/taglib/toolkit/tutils.h b/taglib/toolkit/tutils.h index a1ca76fb..9116c2c3 100644 --- a/taglib/toolkit/tutils.h +++ b/taglib/toolkit/tutils.h @@ -216,20 +216,9 @@ namespace TagLib BigEndian }; -#ifdef SYSTEM_BYTEORDER - -# if SYSTEM_BYTEORDER == 1 - - const ByteOrder SystemByteOrder = LittleEndian; - -# else - - const ByteOrder SystemByteOrder = BigEndian; - -# endif - -#else - + /*! + * Returns the integer byte order of the system. + */ inline ByteOrder systemByteOrder() { union { @@ -244,10 +233,6 @@ namespace TagLib return BigEndian; } - const ByteOrder SystemByteOrder = systemByteOrder(); - -#endif - /*! * Returns the IEEE754 byte order of the system. */ -- 2.40.0