Messages in this thread | | | From | Rusty Russell <> | Subject | Re: [TRIVIAL] kstrdup | Date | Sat, 19 Apr 2003 18:28:24 +1000 |
| |
In message <3EA0D524.7010309@pobox.com> you write: > Since the kernel does its own string ops, the compiler does not have > enough information to deduce that further optimization is possible.
You're right, I was measuring without the kernel string ops. > > Case in point: gcc-3.2 on -O2 on Intel is one instruction longer for > > your version. > > And? It's still slower.
Who gives a flying fuck? You're doing an allocation in there ferchissakes. Choose the simplest option. Jeff, if you have time to post on this, I think you need a hobby 8)
char *__constant_kstrdup(const char *s, unsigned int size, int gfp) { char *buf = kmalloc(size, gfp); if (likely(buf)) memcpy(buf, s, size); return buf; }
char *__kstrdup(const char *s, int gfp) { return __constant_kstrdup(s, strlen(s)+1, gfp); }
#define kstrdup(str, gfp) \ (__builtin_constant_p(str) && sizeof(str) != sizeof(char *) ? \ __constant_kstrdup(str, sizeof(str), gfp) \ : __kstrdup(str, gfp))
Feature list: 1) Optimizes the constant kstrdup case, 2) Doesn't multi-evaluate args (except if constant string), 3) Uses likely() to bias against the case of kmalloc failing.
OK, so I guess I need a hobby, too.. Rusty. -- Anyone who quotes me in their sig is an idiot. -- Rusty Russell. - 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/
| |