Added lfs_memlen, replacing lfsr_gdelta_size
This drops the last lfsr_gdelta_* function, which were really just a bunch of somewhat-quirky mem operations. Moving this to lfs_util.h also allows users to override it with hardware-specific tricks, though I think hardware tricks for lfs_memlen will be quite rare. Reverse-order memory optimizations are pretty uncommon... This could also be done with a theoretical memrcchr, if one existed: p = memrcchr(buffer, 0, size); return (p) ? p - buffer : 0; But I figured this use case is so niche we might as well just limit it to c=0 (and avoid questions about memrchr). No code changes.
This commit is contained in:
+10
@@ -473,6 +473,16 @@ static inline void *lfs_memcchr(const void *a, int c, size_t size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Find the minimum length that includes all non-zero bytes
|
||||
static inline size_t lfs_memlen(const void *a, size_t size) {
|
||||
const uint8_t *a_ = a;
|
||||
while (size > 0 && a_[size-1] == 0) {
|
||||
size -= 1;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
// Xor n bytes from b into a
|
||||
static inline void *lfs_memxor(
|
||||
void *restrict a, const void *restrict b, size_t size) {
|
||||
|
||||
Reference in New Issue
Block a user