lkml.org 
[lkml]   [2000]   [Feb]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: Improved <linux/lists.h>
On Wed, Feb 23, 2000 at 01:02:45PM -0500, Jeff Garzik wrote:
> > Also sprach Borislav Deianov:
> > } On Tue, Feb 22, 2000 at 07:02:53PM -0500, Jeff Garzik wrote:
> > } >
> > } > One technique which is used in the kernel is to, if possible, place the
> > } > primary list_head member of a structure at the top of the struct.
> > } >
> > } > This allows you to reference the structure itself as if it were a list,
> > } > sometimes saving you a few keystrokes...
> > }
> > } Sounds dodgy to me... You still need a cast, and then one day you'll
> > } forget and rearrange the fields of your struct and the compiler won't
> > } even warn you. Maybe places in the kernel that do that should be
> > } fixed?
>
> Look at how the PCI code stores the list of pci_drivers...

OK, that code doesn't *depend* on the list_head being the first member
of the struct (i.e. it always calls list_entry, and takes &drv->node,
etc. where necessary). So it doesn't save you keystrokes but it does
save you a few cycles since you don't need to mess with offsets at
runtime to get to the struct. Cool micro-optimization, agreed.

> Bill Wendling wrote:
> > Plus, as per the CodingStyle doc, it's a "feature" of C. One that escapes
> > the mind of most programmers, especially newer ones. Saving keystrokes
> > shouldn't be the goal. Speeding up code should be the goal.

Can't find a reference to anything like this in CodingStyle...

Best,
Borislav

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

\
 
 \ /
  Last update: 2005-03-22 13:56    [W:0.046 / U:0.420 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site