From a7a9c39db985f21b080a7fb980f6eadcfe7611f1 Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Sun, 10 Nov 2024 08:27:55 -0600 Subject: [PATCH] Don't use memcpy when grabbing single bytes from the buffer --- src/lib/util/dbuff.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/util/dbuff.h b/src/lib/util/dbuff.h index 37b0db35900d..521166150f82 100644 --- a/src/lib/util/dbuff.h +++ b/src/lib/util/dbuff.h @@ -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 @@ -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)), \