Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Improving resizehistents()
- X-seq: zsh-workers 16625
- From: Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx>
- To: Zsh Workers <zsh-workers@xxxxxxxxxx>
- Subject: Re: Improving resizehistents()
- Date: Wed, 13 Feb 2002 11:32:22 -0800 (PST)
- In-reply-to: <Pine.LNX.4.33L2.0202131020580.20999-100000@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
On Wed, 13 Feb 2002, Wayne Davison wrote:
> I've appended a diff between my first patch and the new code.
Yeesh. That function was totally wacked except when there were no dups.
This version appears to work both correctly and quickly.
..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/hist.c
--- Src/hist.c 13 Feb 2002 18:13:14 -0000 1.38
+++ Src/hist.c 13 Feb 2002 19:21:26 -0000
@@ -914,25 +914,31 @@
}
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 @@
histlinect++;
}
else {
- putoldhistentryontop();
+ putoldhistentryontop(0);
freehistdata(hist_ring, 0);
}
hist_ring->histnum = ++curhist;
@@ -1762,9 +1768,13 @@
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);
+ }
}
}
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Messages sorted by:
Reverse Date,
Date,
Thread,
Author