Re: g_str_hash
- From: Havoc Pennington <hp redhat com>
- To: gtk-devel-list redhat com
- Subject: Re: g_str_hash
- Date: 11 Feb 2000 01:49:51 -0500
Havoc Pennington <hp@redhat.com> writes:
> guint
> tcl_hash(gconstpointer v)
> {
> const char* string = (char*)v;
> unsigned int result = 0;
> int c;
>
> while (1) {
> c = *string;
> string++;
> if (c == 0) {
> break;
> }
> result += (result<<3) + c;
> }
> return result;
> }
>
Of course this function can just be:
{
const gchar* s = (char*)v;
guint result = 0;
while (*s)
{
result += (result << 3) + *s;
++s;
}
return result;
}
And it's even microscopically but measurably faster that way. Don't
ask me what's up with the structure of the original version's loop.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]