From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuMKF-00073p-CJ for qemu-devel@nongnu.org; Mon, 18 May 2015 10:47:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuMK8-0007Zv-K0 for qemu-devel@nongnu.org; Mon, 18 May 2015 10:47:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33077) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuMK8-0007Zq-Dl for qemu-devel@nongnu.org; Mon, 18 May 2015 10:47:20 -0400 Message-ID: <5559FB76.3080003@redhat.com> Date: Mon, 18 May 2015 08:47:18 -0600 From: Eric Blake MIME-Version: 1.0 References: <1431948138-14238-1-git-send-email-hw.claudio@gmail.com> <1431948138-14238-2-git-send-email-hw.claudio@gmail.com> In-Reply-To: <1431948138-14238-2-git-send-email-hw.claudio@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="aUEoWLMOikmCUg9SP1tcUCC1Jst7Ahivd" Subject: Re: [Qemu-devel] [RFC v6 1/2] util: add memmem replacement function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: hw.claudio@gmail.com, Luiz Capitulino , Paolo Bonzini Cc: Peter Maydell , Gonglei , Claudio Fontana , qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --aUEoWLMOikmCUg9SP1tcUCC1Jst7Ahivd Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/18/2015 05:22 AM, hw.claudio@gmail.com wrote: > From: Claudio Fontana >=20 > if the memmem function is missing, provide a trivial replacement. >=20 > Signed-off-by: Claudio Fontana > --- > 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 >=20 > + if (s_len =3D=3D 1) { > + return memchr(hay, s[0], hay_len); > + } > + > + for (; hay <=3D last; hay++) { > + if (hay[0] =3D=3D s[0] && memcmp(hay, s, s_len) =3D=3D 0) { An obvious optimization would be: if (hay[0] =3D=3D s[0] && memcmp(hay + 1, s + 1, s_len - 1) =3D=3D 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-i= s. Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --aUEoWLMOikmCUg9SP1tcUCC1Jst7Ahivd Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVWft2AAoJEKeha0olJ0NqZW0H/1xLVmqq3XaQ8WTQqu5H9EL4 PNjKY0QqVpmkhLbMolE9Qc7983jdFTC6AHwuZ5jjyC1v2/5+g5666U7iYlDo+lmd rWJ/INiFc+XOZngXsSZd2+7v2/TKtPW3pqnssM1ku+OpNLAncA2vnpGcswj7aaFL 0eB5ufFxt9XxToSB3Z9zmTTAsctvdBVnIXOWdiIt2oIvDbOWsLMaXy8zMVuhNL1p zTIeFyBtTDqvExaprr24ITIhhHJeWOSDtn019JIbPBY4wmu7fdE57efSkENN5N1r 3smLgIAmZKg1aV0mUQ61uvR8lMqvO6vKaeQ9YLWb5b2QvY+PNDOWbG2rUStBd1o= =8h3H -----END PGP SIGNATURE----- --aUEoWLMOikmCUg9SP1tcUCC1Jst7Ahivd--