about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWayne Davison <wayned@users.sourceforge.net>2002-02-16 09:15:07 +0000
committerWayne Davison <wayned@users.sourceforge.net>2002-02-16 09:15:07 +0000
commite706f12937ff7554c070d45c2810b49a4cff72aa (patch)
tree1b753827f50c92388984be59d5a2db1e8ca40cb8
parent86aa24922bd3eb847f8467e2024e8f3d8a235c23 (diff)
downloadzsh-e706f12937ff7554c070d45c2810b49a4cff72aa.tar.gz
zsh-e706f12937ff7554c070d45c2810b49a4cff72aa.tar.xz
zsh-e706f12937ff7554c070d45c2810b49a4cff72aa.zip
Optimized putoldhistentryontop() so that when resizehistents() calls it
repeatedly while HIST_EXPIRE_DUPS_FIRST is set, it doesn't re-scan the
already-checked hist items (avoiding potentially slow operation).
-rw-r--r--Src/hist.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/Src/hist.c b/Src/hist.c
index dbd3ce1bc..2598baa5c 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -914,25 +914,31 @@ gethistent(int ev, int nearmatch)
 }
 
 static void
-putoldhistentryontop(void)
+putoldhistentryontop(short keep_going)
 {
-    Histent he = hist_ring->down;
+    static Histent next = NULL;
+    Histent he = keep_going? next : hist_ring->down;
+    next = he->down;
     if (isset(HISTEXPIREDUPSFIRST) && !(he->flags & HIST_DUP)) {
-	int max_unique_ct = getiparam("SAVEHIST");
+	static int max_unique_ct = 0;
+	if (!keep_going)
+	    max_unique_ct = getiparam("SAVEHIST");
 	do {
 	    if (max_unique_ct-- <= 0) {
+		max_unique_ct = 0;
 		he = hist_ring->down;
 		break;
 	    }
-	    he = he->down;
+	    he = next;
+	    next = he->down;
 	} while (he != hist_ring->down && !(he->flags & HIST_DUP));
-	if (he != hist_ring->down) {
-	    he->up->down = he->down;
-	    he->down->up = he->up;
-	    he->up = hist_ring;
-	    he->down = hist_ring->down;
-	    hist_ring->down = he->down->up = he;
-	}
+    }
+    if (he != hist_ring->down) {
+	he->up->down = he->down;
+	he->down->up = he->up;
+	he->up = hist_ring;
+	he->down = hist_ring->down;
+	hist_ring->down = he->down->up = he;
     }
     hist_ring = he;
 }
@@ -963,7 +969,7 @@ prepnexthistent(void)
 	histlinect++;
     }
     else {
-	putoldhistentryontop();
+	putoldhistentryontop(0);
 	freehistdata(hist_ring, 0);
     }
     hist_ring->histnum = ++curhist;
@@ -1762,9 +1768,13 @@ inithist(void)
 void
 resizehistents(void)
 {
-    while (histlinect > histsiz) {
-	putoldhistentryontop();
+    if (histlinect > histsiz) {
+	putoldhistentryontop(0);
 	freehistnode((HashNode)hist_ring);
+	while (histlinect > histsiz) {
+	    putoldhistentryontop(1);
+	    freehistnode((HashNode)hist_ring);
+	}
     }
 }