From: Sami Kerola Date: Sun, 30 Jun 2013 08:44:00 +0000 (+0100) Subject: ul: enhance command performance X-Git-Tag: v2.24-rc1~467 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99361a9c0e2a93ab8a21a675f74178700457f838;p=thirdparty%2Futil-linux.git ul: enhance command performance Avoid reseting, time after time, the memory which was not used. Effect of the change is below in before and after timings. $ time ./ul /dev/null real 0m0.320s user 0m0.307s sys 0m0.010s $ time ./ul /dev/null real 0m0.068s user 0m0.050s sys 0m0.017s [kzak@redhat.com: - add "else" and use maxcol] Signed-off-by: Sami Kerola Signed-off-by: Karel Zak --- diff --git a/text-utils/ul.c b/text-utils/ul.c index 5710a5547e..7b50ede509 100644 --- a/text-utils/ul.c +++ b/text-utils/ul.c @@ -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;