Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys/lib/libkern



> On Thu, Nov 22, 2007 at 12:15:47PM +0900, YAMAMOTO Takashi wrote:
> > > On Thu, Nov 22, 2007 at 11:31:44AM +0900, YAMAMOTO Takashi wrote:
> > > > how about returning the duplicate node rather than a boolean?
> > > 
> > > I don't think that is a common use case. E.g. normally insert is used to
> > > prepare a new node and a duplicate entry is an actual error. I can't
> > > think of a good example where you want to replace the existing entry and
> > > didn't check for that earlier.
> > > 
> > > Joerg
> > 
> > i'm not suggesting to automatically replace an existing node.
> 
> No, but for what other reason should it return a pointer to the existing
> node?
> 
> Joerg

i think a pointer is better because:
- a caller might want to investigate a duplicate entry.
  for example, lockdebug_alloc dumps a duplicate entry.
  i don't know if it's common or rare, but the cost to return a pointer
  is negligible.
- a pointer can be trivially converted to a boolean if you want, while
  the opposite requires relookup.
- i keep to forget which of true or false is an error.  :)

can you explain why you think a boolean is better?

YAMAMOTO Takashi



Home | Main Index | Thread Index | Old Index