]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ul: enhance command performance
authorSami Kerola <kerolasa@iki.fi>
Sun, 30 Jun 2013 08:44:00 +0000 (09:44 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 1 Jul 2013 12:02:57 +0000 (14:02 +0200)
Avoid reseting, time after time, the memory which was not used.  Effect
of the change is below in before and after timings.

$ time ./ul </etc/services >/dev/null
real    0m0.320s
user    0m0.307s
sys     0m0.010s

$ time ./ul </etc/services >/dev/null
real    0m0.068s
user    0m0.050s
sys     0m0.017s

[kzak@redhat.com: - add "else" and use maxcol]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/ul.c

index 5710a5547e98870448b4ddfd80e686dada0ac38a..7b50ede509edd51c528357fd8355ca84bed62420 100644 (file)
@@ -491,11 +491,11 @@ static void initbuf(void)
        if (obuf == NULL) {
                /* First time. */
                obuflen = BUFSIZ;
-               obuf = xmalloc(sizeof(struct CHAR) * obuflen);
-       }
+               obuf = xcalloc(obuflen, sizeof(struct CHAR));
+       } else
+               /* assumes NORMAL == 0 */
+               memset(obuf, 0, sizeof(struct CHAR) * maxcol);
 
-       /* assumes NORMAL == 0 */
-       memset(obuf, 0, sizeof(struct CHAR) * obuflen);
        setcol(0);
        maxcol = 0;
        mode &= ALTSET;