Get rid of additional memcpy calls
This commit is contained in:
parent
21f7ca2fb3
commit
088f9a6c32
2 changed files with 6 additions and 24 deletions
|
@ -51,24 +51,15 @@
|
|||
#define convert_from_le64(x)
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
static inline void convert_from_le16(void * value) {
|
||||
uint16_t temp;
|
||||
memcpy(&temp, value, sizeof(uint16_t));
|
||||
temp = le16toh(temp);
|
||||
memcpy(value, &temp, sizeof(uint16_t));
|
||||
*((uint16_t*)value) = le16toh(*((uint16_t*)value));
|
||||
}
|
||||
|
||||
static inline void convert_from_le32(void * value) {
|
||||
uint32_t temp;
|
||||
memcpy(&temp, value, sizeof(uint32_t));
|
||||
temp = le32toh(temp);
|
||||
memcpy(value, &temp, sizeof(uint32_t));
|
||||
*((uint32_t*)value) = le32toh(*((uint32_t*)value));
|
||||
}
|
||||
|
||||
static inline void convert_from_le64(void * value) {
|
||||
uint64_t temp;
|
||||
memcpy(&temp, value, sizeof(uint64_t));
|
||||
temp = le64toh(temp);
|
||||
memcpy(value, &temp, sizeof(uint64_t));
|
||||
*((uint64_t*)value) = le64toh(*((uint64_t*)value));
|
||||
}
|
||||
#else
|
||||
#error Unexpected or undefined __BYTE_ORDER__
|
||||
|
|
|
@ -36,26 +36,17 @@ static inline void convert_from_le(T * /*value*/)
|
|||
|
||||
template <typename T, std::enable_if_t<sizeof(T) == 2, int> = 0>
|
||||
static inline void convert_from_le(T * value) {
|
||||
uint16_t temp;
|
||||
memcpy(&temp, value, sizeof(uint16_t));
|
||||
temp = le16toh(temp);
|
||||
memcpy(value, &temp, sizeof(uint16_t));
|
||||
*((uint16_t*)value) = le16toh(*((uint16_t*)value));
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<sizeof(T) == 4, int> = 0>
|
||||
static inline void convert_from_le(T * value) {
|
||||
uint32_t temp;
|
||||
memcpy(&temp, value, sizeof(uint32_t));
|
||||
temp = le32toh(temp);
|
||||
memcpy(value, &temp, sizeof(uint32_t));
|
||||
*((uint32_t*)value) = le32toh(*((uint32_t*)value));
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<sizeof(T) == 8, int> = 0>
|
||||
static inline void convert_from_le(T * value) {
|
||||
uint64_t temp;
|
||||
memcpy(&temp, value, sizeof(uint64_t));
|
||||
temp = le64toh(temp);
|
||||
memcpy(value, &temp, sizeof(uint64_t));
|
||||
*((uint64_t*)value) = le64toh(*((uint64_t*)value));
|
||||
}
|
||||
#else
|
||||
#error Unexpected or undefined __BYTE_ORDER__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue