Run-time check for integer byte order rather than CMake check.

It will easily be optimized out.
This commit is contained in:
Tsuda Kageyu
2015-08-03 13:08:58 +09:00
parent 44d9f2bf25
commit 076e845912
5 changed files with 6 additions and 36 deletions

View File

@ -209,7 +209,7 @@ T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignifica
template <class T>
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 <class T>
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)

View File

@ -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;
}

View File

@ -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.
*/