From 217b0b07917ac5f475a49566515dbb0dd718e9e3 Mon Sep 17 00:00:00 2001 From: Vincent Labrecque Date: Wed, 13 Feb 2002 22:36:59 +0000 Subject: Make mg malloc the l_text element instead of reallocating whole LINE structures all the time. --- usr.bin/mg/kbd.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'usr.bin/mg/kbd.c') diff --git a/usr.bin/mg/kbd.c b/usr.bin/mg/kbd.c index 0cd3f1dd4fe..21a49f86c85 100644 --- a/usr.bin/mg/kbd.c +++ b/usr.bin/mg/kbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kbd.c,v 1.10 2001/05/24 03:05:23 mickey Exp $ */ +/* $OpenBSD: kbd.c,v 1.11 2002/02/13 22:36:58 vincent Exp $ */ /* * Terminal independent keyboard handling. @@ -375,28 +375,20 @@ selfinsert(f, n) /* last command was insert -- tack on the end */ if (lastflag & CFINS) { macrocount--; + /* Ensure the line can handle the new characters */ if (maclcur->l_size < maclcur->l_used + n) { - if ((lp = lallocx(maclcur->l_used + n)) == NULL) + if (lrealloc(maclcur, maclcur->l_used + n) == + FALSE) return FALSE; - lp->l_fp = maclcur->l_fp; - lp->l_bp = maclcur->l_bp; - lp->l_fp->l_bp = lp->l_bp->l_fp = lp; - bcopy(maclcur->l_text, lp->l_text, - maclcur->l_used); - for (count = maclcur->l_used; - count < lp->l_used; count++) - lp->l_text[count] = c; - free((char *)maclcur); - maclcur = lp; - } else { - maclcur->l_used += n; - for (count = maclcur->l_used - n; - count < maclcur->l_used; count++) - maclcur->l_text[count] = c; } + maclcur->l_used += n; + /* Copy in the new data */ + for (count = maclcur->l_used - n; + count < maclcur->l_used; count++) + maclcur->l_text[count] = c; } else { macro[macrocount - 1].m_funct = insert; - if ((lp = lallocx(n)) == NULL) + if ((lp = lalloc(n)) == NULL) return FALSE; lp->l_bp = maclcur; lp->l_fp = maclcur->l_fp; -- cgit v1.2.3