Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE

Rogier Wolff (R.E.Wolff@BitWizard.nl)
Fri, 11 Jul 2003 11:50:01 +0200


On Sat, May 24, 2003 at 08:52:53PM -0700, Linus Torvalds wrote:
> How about just adding a sane
>
> int copy_string(char *dest, const char *src, int len)
> {
> int size;
>
> if (!len)
> return 0;
> size = strlen(src);
> if (size >= len)
> size = len-1;
> memcpy(dest, src, size);
> dest[size] = '\0';
> return size;
> }

Just catching up...

Most people will think: "But that's not efficient!" he first
determines the size using strlen, and only then does he start a
memcpy.

In fact most modern processors priming the cache and then doing the
copy is noticably faster or just a teeny little bit slower.

Roger.

-- 
** R.E.Wolff@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2600998 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
* I didn't say it was your fault. I said I was going to blame it on you. *
-
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/