This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add inline bsearch expansion


On Sat, Jan 05, 2013 at 04:43:33PM +0100, Andreas Schwab wrote:
> OndÅej BÃlka <neleai@seznam.cz> writes:
> 
> > +bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
> > +   int (*__compar) (const void *, const void *))
> > +{
> > +  size_t __l, __u, __idx;
> > +  const void *__p;
> > +  int __comparison;
> > +
> > +  __l = 0;
> > +  __u = __nmemb;
> > +  while (__l < __u)
> > +    {
> > +      __idx = (__l + __u) / 2;
> > +      __p = (void *) (((const char *) __base) + (__idx * __size));
> > +      __comparison = (*__compar) (__key, __p);
> > +      if (__comparison < 0)
> > +  __u = __idx;
> > +      else if (__comparison > 0)
> > +  __l = __idx + 1;
> > +      else
> > +  return (void *) __p;
> > +    }
> 
> Please use proper indentation.
OK

Also as I said that knowing size is possible optimization it does not
provide speedup on sandy bridge. Probably only atom would benefit which
is IMO not enough.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]