This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
More backref performance - no strncmp
- From: "Paolo Bonzini" <paolo dot bonzini at polimi dot it>
- To: <libc-alpha at sources dot redhat dot com>
- Date: Thu, 24 Oct 2002 11:21:15 +0200
- Subject: More backref performance - no strncmp
- Reply-to: "Paolo Bonzini" <bonzini at gnu dot org>
> Note you cannot be ever sure regex won't have to compare 4K or
> longer strings, at which point at least on most arches my_memcmp
> will be way slower (lot of memcmp implementations compare 4 or
> 8 bytes at a time).
You're right, but I based my implementation on sed, which is probably the
most aggressive user of backreferences, because it is common to use them to
implement lookup tables such as this
:y
y/abcdefg/bcdefgh/
s/$/;01a2aa3aaa4aaaa etc/
s/\([0-9]\)\([0-9]*\);.*\1\(a*\).*/\3\2/
/[0-9]/by
For large strings, memcmp is indeed faster, but I think that using memcmp is
out of discussion because it incurs a 20% performance loss with respect to
strncmp due to startup overhead on small strings.
Anyway using strncmp is incorrect when there are nuls, and this ought to be
fixed. Maybe unroll my_memcmp?
Paolo