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:
Christopher Haster
2025-01-18 16:10:31 -06:00
parent bac61a120b
commit bc959e4d0e
2 changed files with 14 additions and 14 deletions
+10
View File
@@ -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) {