On 05/18/2015 05:22 AM, [email protected] wrote: > From: Claudio Fontana <[email protected]> > > if the memmem function is missing, provide a trivial replacement. > > Signed-off-by: Claudio Fontana <[email protected]> > --- > 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 <[email protected]>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
