]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: optimize string initializations
authorSami Kerola <kerolasa@iki.fi>
Sat, 9 Aug 2014 07:38:58 +0000 (08:38 +0100)
committerSami Kerola <kerolasa@iki.fi>
Fri, 15 Aug 2014 20:52:12 +0000 (21:52 +0100)
Setting whole array to be completely full of nulls cannot be as quick as
making the only significant member of the array when needed.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/logger.c

index 8ae00b26a5d75ec26e6df77b1a44fa927627e0e0..884a1197b0f0d5b1088471a291a51e90712fd6e7 100644 (file)
@@ -299,11 +299,12 @@ static pid_t get_process_id(struct logger_ctl *ctl)
 
 static void syslog_rfc3164(struct logger_ctl *ctl, char *msg)
 {
-       char *buf, pid[30] = { '\0' }, *cp, *tp, *hostname, *dot;
+       char *buf, pid[30], *cp, *tp, *hostname, *dot;
        time_t now;
        pid_t process;
        int len;
 
+       *pid = '\0';
        if (ctl->fd < 0)
                return;
        if ((process = get_process_id(ctl)))
@@ -334,13 +335,14 @@ static void syslog_rfc3164(struct logger_ctl *ctl, char *msg)
 static void syslog_rfc5424(struct logger_ctl *ctl, char *msg)
 {
        char *buf, *tag = NULL, *hostname = NULL;
-       char pid[32] = { '\0' }, time[64] = { '\0' }, timeq[80] = { '\0' };
+       char pid[32], time[64], timeq[80];
        struct ntptimeval ntptv;
        struct timeval tv;
        struct tm *tm;
        pid_t process;
        int len;
 
+       *pid = *time = *timeq = '\0';
        if (ctl->fd < 0)
                return;