This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: just a little nitpik in bfd
- From: Nick Clifton <nickc at cambridge dot redhat dot com>
- To: Stuart Balfour <sbalfour at cisco dot com>
- Cc: binutils at sources dot redhat dot com
- Date: 17 May 2002 10:20:15 +0100
- Subject: Re: just a little nitpik in bfd
- References: <200205122056.NAA09948@cisco.com>
Hi Stuart,
> In the core of bfd (binutils 2.11.92), in file hash.c in function
> bfd_hash_lookup, I see:
>
> > hash = 0;
> > len = 0;
> > s = (const unsigned char *) string;
> > while ((c = *s++) != '\0')
> > {
> > hash += c + (c << 17);
> > hash ^= hash >> 2;
> > ++len;
> > }
> > hash += len + (len << 17);
> > hash ^= hash >> 2;
>
> Surely, we can eliminate ++len from the loop, because it is an
> induction variable (and the compiler might do it for us, but we can
> and should code carefully first, then hope the compiler can do
> better):
Certainly - that would be a reasonable change - I will apply the patch
shortly.
> One more wrinkle: why do we need to hash len into the hash total?
It does no harm, and it might help in situations where a long string
with low numbered ascii characters has a similar hash value to a
shorter string with higher numbered ascii characters.
Cheers
Nick