[PATCH 1/2] string: add mem_is_zero() helper to check if memory area is all zeros
Andy Shevchenko
andy.shevchenko at gmail.com
Mon May 27 13:27:05 UTC 2024
On Mon, May 27, 2024 at 12:43 PM Jani Nikula <jani.nikula at intel.com> wrote:
>
> Almost two thirds of the memchr_inv() usages check if the memory area is
> all zeros, with no interest in where in the buffer the first non-zero
> byte is located. Checking for !memchr_inv(s, 0, n) is also not very
> intuitive or discoverable. Add an explicit mem_is_zero() helper for this
> use case.
...
> +static inline bool mem_is_zero(const void *s, size_t n)
> +{
> + return !memchr_inv(s, 0, n);
> +}
There are potential users for the 0xff check as well. Hence the
following question:
Are we going to have a new function per byte in question, or do we
come up with a common denominator, like mem_is_all_of(mem, byte)?
--
With Best Regards,
Andy Shevchenko
More information about the dri-devel
mailing list