Re: [TRIVIAL] kstrdup

From: Jeff Garzik (
Date: Fri Apr 18 2003 - 23:48:36 EST

Rusty Russell wrote:
> In message <> you write:
>>Rusty Trivial Russell wrote:
>>>+char *kstrdup(const char *s, int gfp)
>>>+ char *buf = kmalloc(strlen(s)+1, gfp);
>>>+ if (buf)
>>>+ strcpy(buf, s);
>>>+ return buf;
>>You should save the strlen result to a temp var, and then s/strcpy/memcpy/
> Completely disagree. Write the most straightforward code possible,
> and then if there proves to be a problem, optimize. Optimizations
> where there's no actual performance problem should be left to the
> compiler.

Since the kernel does its own string ops, the compiler does not have
enough information to deduce that further optimization is possible.

> Case in point: gcc-3.2 on -O2 on Intel is one instruction longer for
> your version.

And? It's still slower.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Wed Apr 23 2003 - 22:00:25 EST