[hackers] [sbase] Improve doglobal()

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Tue, 6 Mar 2018 18:39:04 +0100

Don't use directly the line numbers and call to getlst()
when a line is matched.
---
 ed.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/ed.c b/ed.c
index 13c41c6..e6d92e2 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -1318,7 +1318,7 @@ chkglobal(void)
 static void
 doglobal(void)
 {
-	int i, k;
+	int cnt, ln, k;
 
 	skipblank();
 	cmdline.siz = 0;
_AT_@ -1326,18 +1326,24 @@ doglobal(void)
 	if (uflag)
 		chkprint(0);
 
-	for (i = 1; i <= lastln; i++) {
-		k = getindex(i);
-		if (!zero[k].global)
-			continue;
-		curln = i;
-		nlines = 0;
-		if (uflag) {
-			line1 = line2 = i;
-			pflag = 0;
-			doprint();
+	ln = line1;
+	for (cnt = 0; cnt < lastln;) {
+		k = getindex(ln);
+		if (zero[k].global) {
+			zero[k].global = 0;
+			curln = ln;
+			nlines = 0;
+			if (uflag) {
+				line1 = line2 = ln;
+				pflag = 0;
+				doprint();
+			}
+			getlst();
+			docmd();
+		} else {
+			cnt++;
+			ln = nextln(ln);
 		}
-		docmd();
 	}
 	discard();   /* cover the case of not matching anything */
 }
-- 
2.16.2
Received on Tue Mar 06 2018 - 18:39:04 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 06 2018 - 18:48:25 CET