Re: [PATCH] memchr (trivial) optimization

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

 



On Fri, Aug 24, 2007 at 02:54:48PM +0200, Jan Engelhardt wrote:
> 
> On Aug 23 2007 19:13, Matt Mackall wrote:
> >
> >And you can do even better with this:
> >
> >void *memchr(const void *s, int c, size_t n)
> >{
> >       const unsigned char *p = s, *e = s + n;
> >       const unsigned char *e = p + n;
> 
> Uhm, you have two "e"s in there.

Yep, that's what I get for editing in email.

> Or do it glibc-style
> 
> void *memchr(const void *s, unsigned char c, size_t n)
> {
> 	...
> 	for (; p + 3 < e; p += 4) {
> 		if (c == p[0])
> 			return (void *)&p[0];
> 		if (c == p[1])
> 			return (void *)&p[1];
> 		if (c == p[2])
> 			return (void *)&p[2];
> 		if (c == p[3])
> 			return (void *)&p[3];
> 	}
> 	... /* check the rest */
> }

Yes, very funny.

-- 
Mathematics is the supreme nostalgia of our time.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux