From 99361a9c0e2a93ab8a21a675f74178700457f838 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 30 Jun 2013 09:44:00 +0100 Subject: 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 --- text-utils/ul.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'text-utils') diff --git a/text-utils/ul.c b/text-utils/ul.c index 5710a5547..7b50ede50 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; -- cgit v1.2.3-55-g7522