[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC v6 1/2] util: add memmem replacement function
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [RFC v6 1/2] util: add memmem replacement function |
Date: |
Mon, 18 May 2015 08:47:18 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
On 05/18/2015 05:22 AM, address@hidden wrote:
> From: Claudio Fontana <address@hidden>
>
> if the memmem function is missing, provide a trivial replacement.
>
> Signed-off-by: Claudio Fontana <address@hidden>
> ---
> configure | 15 +++++++++++++
> include/qemu/osdep.h | 4 ++++
> util/Makefile.objs | 1 +
> util/memmem.c | 62
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 82 insertions(+)
> create mode 100644 util/memmem.c
>
> + if (s_len == 1) {
> + return memchr(hay, s[0], hay_len);
> + }
> +
> + for (; hay <= last; hay++) {
> + if (hay[0] == s[0] && memcmp(hay, s, s_len) == 0) {
An obvious optimization would be:
if (hay[0] == s[0] && memcmp(hay + 1, s + 1, s_len - 1) == 0)
since you already compared the first byte and know that the needle is
more than one byte.
But it's not worth the churn; this version is sufficient for the job as-is.
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature