mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-11-01 00:51:08 +03:00
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>
This commit is contained in:
parent
b29a5e4ab9
commit
fa0e955a93
@ -114,7 +114,6 @@ size_t util_path_encode(char *s, size_t len)
|
|||||||
char t[(len * 3)+1];
|
char t[(len * 3)+1];
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
|
||||||
t[0] = '\0';
|
|
||||||
for (i = 0, j = 0; s[i] != '\0'; i++) {
|
for (i = 0, j = 0; s[i] != '\0'; i++) {
|
||||||
if (s[i] == '/') {
|
if (s[i] == '/') {
|
||||||
memcpy(&t[j], "\\x2f", 4);
|
memcpy(&t[j], "\\x2f", 4);
|
||||||
@ -127,8 +126,11 @@ size_t util_path_encode(char *s, size_t len)
|
|||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t[j] = '\0';
|
if (len == 0)
|
||||||
strncpy(s, t, len);
|
return j;
|
||||||
|
i = (j < len - 1) ? j : len - 1;
|
||||||
|
memcpy(s, t, i);
|
||||||
|
s[i] = '\0';
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user