lkml.org 
[lkml]   [2007]   [Aug]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [patch 1/4] Linux Kernel Markers - Architecture Independent Code
From
Date
On Fri, 2007-08-24 at 12:26 -0400, Mathieu Desnoyers wrote:
> * Rusty Russell (rusty@rustcorp.com.au) wrote:
> > On Mon, 2007-08-20 at 16:27 -0400, Mathieu Desnoyers wrote:
> > > +{
> > > + struct hlist_head *head;
> > > + struct hlist_node *node;
> > > + struct marker_entry *e;
> > > + size_t len = strlen(name) + 1;
> > > + u32 hash = jhash(name, len-1, 0);
> > > +
> > > + head = &marker_table[hash & ((1 << MARKER_HASH_BITS)-1)];
> > > + hlist_for_each_entry(e, node, head, hlist) {
> > > + if (!strcmp(name, e->name))
> > > + return e;
> > > + }
> > > + return NULL;
> > > +}
> >
> > OK, don't understand the strlen, len, len-1 dance here?
> >
>
> Let's say we have abc\0 for marker name as name input.
>
> len = 3 + 1 = 4 (including \0)
> hash is done only on the 3 first chars, excluding the \0 (therefore the
> len-1 there)
>
> Actually, it's like this only for a matter of consistency between
> add_marker and remove_marker, which are quite similar, but add_marker
> needs name_len to include the \0 value. It would be odd to change the
> logic between the two functions to one including the \0 and the other
> excluding it.

Sure, but that doesn't really explain why the code does:

size_t len = strlen(name) + 1;
u32 hash = jhash(name, len-1, 0);

Rather than:

u32 hash = jhash(name, strlen(name), 0);

> Thanks for the review,

That's fine, just some light reading...

Cheers,
Rusty.
>

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-08-25 22:53    [W:0.050 / U:0.756 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site