diff options
author | Alan Jenkins <alan-jenkins@tuffmail.co.uk> | 2008-10-21 11:12:57 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-21 13:09:31 +0200 |
commit | fa0e955a93ca7d7e90d286a68454c6bd808a1c01 (patch) | |
tree | a22ed095c03e134718a9b95dd154a67dbebaad41 /udev/lib | |
parent | b29a5e4ab98f460d2f79a11d1969858640e897e6 (diff) |
libudev: util - optimize path_encode()
Since we already know the length, use memcpy() instead.
Measured 2% _user_ cpu time reduction on EeePC coldplug.
Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Diffstat (limited to 'udev/lib')
-rw-r--r-- | udev/lib/libudev-util.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/udev/lib/libudev-util.c b/udev/lib/libudev-util.c index 0ff121d774..6586d1c825 100644 --- a/udev/lib/libudev-util.c +++ b/udev/lib/libudev-util.c @@ -114,7 +114,6 @@ size_t util_path_encode(char *s, size_t len) char t[(len * 3)+1]; size_t i, j; - t[0] = '\0'; for (i = 0, j = 0; s[i] != '\0'; i++) { if (s[i] == '/') { memcpy(&t[j], "\\x2f", 4); @@ -127,8 +126,11 @@ size_t util_path_encode(char *s, size_t len) j++; } } - t[j] = '\0'; - strncpy(s, t, len); + if (len == 0) + return j; + i = (j < len - 1) ? j : len - 1; + memcpy(s, t, i); + s[i] = '\0'; return j; } |