[systemd-devel] [PATCH 2/2] RFC: util: Avoid doing work on the string when it is not used
Holger Freyther
holger at freyther.de
Tue Apr 2 13:35:51 PDT 2013
From: Holger Hans Peter Freyther <holger at moiji-mobile.com>
The routine is dominated by the fgets and not the code that is
moved around. Doing the work only for the lines that will be
used should be a small gain. Routines in the selinux-access.c
should probably query the gid and uid at the same time instead
of opening and parsing the file twice.
---
src/shared/util.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/shared/util.c b/src/shared/util.c
index ce8f866..d5ed615 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -746,11 +746,9 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
return -errno;
FOREACH_LINE(line, f, return -errno) {
- char *l;
- l = strstrip(line);
-
- if (startswith(l, field)) {
+ if (startswith(line, field)) {
+ char *l = strstrip(line);
l += strlen(field);
l += strspn(l, WHITESPACE);
--
1.7.10.4
More information about the systemd-devel
mailing list