[PATCH] ul: enhance command performance

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux