qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: hw.claudio@gmail.com, Luiz Capitulino <lcapitulino@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Gonglei <arei.gonglei@huawei.com>,
	Claudio Fontana <claudio.fontana@huawei.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC v6 1/2] util: add memmem replacement function
Date: Mon, 18 May 2015 08:47:18 -0600	[thread overview]
Message-ID: <5559FB76.3080003@redhat.com> (raw)
In-Reply-To: <1431948138-14238-2-git-send-email-hw.claudio@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1151 bytes --]

On 05/18/2015 05:22 AM, hw.claudio@gmail.com wrote:
> From: Claudio Fontana <claudio.fontana@huawei.com>
> 
> if the memmem function is missing, provide a trivial replacement.
> 
> Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
> ---
>  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 <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-05-18 14:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-18 11:22 [Qemu-devel] [RFC v6 0/2] monitor: add memory search commands s, sp hw.claudio
2015-05-18 11:22 ` [Qemu-devel] [RFC v6 1/2] util: add memmem replacement function hw.claudio
2015-05-18 14:47   ` Eric Blake [this message]
2015-05-18 11:22 ` [Qemu-devel] [RFC v6 2/2] monitor: add memory search commands s, sp hw.claudio
2015-05-28 20:18 ` [Qemu-devel] [RFC v6 0/2] " Luiz Capitulino
2015-06-11 17:53   ` Luiz Capitulino
2015-06-12  6:21     ` Markus Armbruster
2015-06-12  8:35       ` Claudio Fontana
2015-06-12 12:57         ` Markus Armbruster
2015-06-12 13:31           ` Claudio Fontana
2015-06-12 22:31             ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5559FB76.3080003@redhat.com \
    --to=eblake@redhat.com \
    --cc=arei.gonglei@huawei.com \
    --cc=claudio.fontana@huawei.com \
    --cc=hw.claudio@gmail.com \
    --cc=lcapitulino@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).