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