public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ul: enhance command performance
@ 2013-06-30  8:44 Sami Kerola
  2013-07-01 12:05 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Sami Kerola @ 2013-06-30  8:44 UTC (permalink / raw)
  To: util-linux; +Cc: kerolasa

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

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 text-utils/ul.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/text-utils/ul.c b/text-utils/ul.c
index 5710a55..572f1b8 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));
 	}
 
 	/* assumes NORMAL == 0 */
-	memset(obuf, 0, sizeof(struct CHAR) * obuflen);
+	memset(obuf, 0, sizeof(struct CHAR) * col);
 	setcol(0);
 	maxcol = 0;
 	mode &= ALTSET;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-07-01 12:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-30  8:44 [PATCH] ul: enhance command performance Sami Kerola
2013-07-01 12:05 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox