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>
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;