Using llvm::sys::swapByteOrder() for the common case of byte-swapping a value in place

llvm-svn: 210978
This commit is contained in:
Artyom Skrobov 2014-06-14 13:18:07 +00:00
parent 33ac4d71e5
commit 8e686bd8fe
5 changed files with 8 additions and 8 deletions

View File

@ -152,7 +152,7 @@ inline uint64_t fetch64(const char *p) {
uint64_t result;
memcpy(&result, p, sizeof(result));
if (sys::IsBigEndianHost)
return sys::getSwappedBytes(result);
sys::swapByteOrder(result);
return result;
}
@ -160,7 +160,7 @@ inline uint32_t fetch32(const char *p) {
uint32_t result;
memcpy(&result, p, sizeof(result));
if (sys::IsBigEndianHost)
return sys::getSwappedBytes(result);
sys::swapByteOrder(result);
return result;
}

View File

@ -38,7 +38,7 @@ namespace endian {
template<typename value_type, endianness endian>
inline value_type byte_swap(value_type value) {
if (endian != native && sys::IsBigEndianHost != (endian == big))
return sys::getSwappedBytes(value);
sys::swapByteOrder(value);
return value;
}

View File

@ -245,14 +245,14 @@ protected:
void writeInt16BE(uint8_t *Addr, uint16_t Value) {
if (IsTargetLittleEndian)
Value = sys::getSwappedBytes(Value);
sys::swapByteOrder(Value);
*Addr = (Value >> 8) & 0xFF;
*(Addr + 1) = Value & 0xFF;
}
void writeInt32BE(uint8_t *Addr, uint32_t Value) {
if (IsTargetLittleEndian)
Value = sys::getSwappedBytes(Value);
sys::swapByteOrder(Value);
*Addr = (Value >> 24) & 0xFF;
*(Addr + 1) = (Value >> 16) & 0xFF;
*(Addr + 2) = (Value >> 8) & 0xFF;
@ -261,7 +261,7 @@ protected:
void writeInt64BE(uint8_t *Addr, uint64_t Value) {
if (IsTargetLittleEndian)
Value = sys::getSwappedBytes(Value);
sys::swapByteOrder(Value);
*Addr = (Value >> 56) & 0xFF;
*(Addr + 1) = (Value >> 48) & 0xFF;
*(Addr + 2) = (Value >> 40) & 0xFF;

View File

@ -1179,7 +1179,7 @@ prependCompressionHeader(uint64_t Size,
if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
return false;
if (sys::IsLittleEndianHost)
Size = sys::getSwappedBytes(Size);
sys::swapByteOrder(Size);
CompressedContents.insert(CompressedContents.begin(),
Magic.size() + sizeof(Size), 0);
std::copy(Magic.begin(), Magic.end(), CompressedContents.begin());

View File

@ -21,7 +21,7 @@ static T getU(uint32_t *offset_ptr, const DataExtractor *de,
if (de->isValidOffsetForDataOfSize(offset, sizeof(val))) {
std::memcpy(&val, &Data[offset], sizeof(val));
if (sys::IsLittleEndianHost != isLittleEndian)
val = sys::getSwappedBytes(val);
sys::swapByteOrder(val);
// Advance the offset
*offset_ptr += sizeof(val);