summaryrefslogtreecommitdiffstats
path: root/text-utils/ul.c
diff options
context:
space:
mode:
authorSami Kerola2013-06-30 10:44:00 +0200
committerKarel Zak2013-07-01 14:02:57 +0200
commit99361a9c0e2a93ab8a21a675f74178700457f838 (patch)
tree17a5e34969b3f956c9b97f9b444bc0b1636bf2aa /text-utils/ul.c
parentexec_shell: add a license and touch up func def (diff)
downloadkernel-qcow2-util-linux-99361a9c0e2a93ab8a21a675f74178700457f838.tar.gz
kernel-qcow2-util-linux-99361a9c0e2a93ab8a21a675f74178700457f838.tar.xz
kernel-qcow2-util-linux-99361a9c0e2a93ab8a21a675f74178700457f838.zip
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 </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>
Diffstat (limited to 'text-utils/ul.c')
-rw-r--r--text-utils/ul.c8
1 files changed, 4 insertions, 4 deletions
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;