Skip to content

Commit

Permalink
Don't use memcpy when grabbing single bytes from the buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Nov 10, 2024
1 parent a60a9c9 commit a7a9c39
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/lib/util/dbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,18 @@ FR_DBUFF_OUT_DEF(uint64)
FR_DBUFF_OUT_DEF(int16)
FR_DBUFF_OUT_DEF(int32)
FR_DBUFF_OUT_DEF(int64)

#define FR_DBUFF_OUT_DEF_NO_SWAP(_type) \
static inline ssize_t _fr_dbuff_out_##_type(_type##_t *out, uint8_t **pos_p, fr_dbuff_t *in) \
{ \
fr_assert(out); \
FR_DBUFF_EXTEND_LOWAT_OR_RETURN(in, sizeof(_type##_t)); \
*out = **pos_p; \
return _fr_dbuff_set(pos_p, in, (*pos_p) + sizeof(_type##_t)); \
}

FR_DBUFF_OUT_DEF_NO_SWAP(uint8)
FR_DBUFF_OUT_DEF_NO_SWAP(int8)
/** @endcond */

/** Copy data from a dbuff or marker to a fixed sized C type
Expand All @@ -1786,11 +1798,11 @@ FR_DBUFF_OUT_DEF(int64)
*/
#define fr_dbuff_out(_out, _dbuff_or_marker) \
_Generic((_out), \
uint8_t * : _fr_dbuff_out_memcpy((uint8_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker), 1), \
uint8_t * : _fr_dbuff_out_uint8((uint8_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker)), \
uint16_t * : _fr_dbuff_out_uint16((uint16_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker)), \
uint32_t * : _fr_dbuff_out_uint32((uint32_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker)), \
uint64_t * : _fr_dbuff_out_uint64((uint64_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker)), \
int8_t * : _fr_dbuff_out_memcpy((uint8_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker), 1), \
int8_t * : _fr_dbuff_out_int8((uint8_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker)), \
int16_t * : _fr_dbuff_out_int16((int16_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker)), \
int32_t * : _fr_dbuff_out_int32((int32_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker)), \
int64_t * : _fr_dbuff_out_int64((int64_t *)(_out), _fr_dbuff_current_ptr(_dbuff_or_marker), fr_dbuff_ptr(_dbuff_or_marker)), \
Expand Down

0 comments on commit a7a9c39

Please sign in to comment.