From e706f12937ff7554c070d45c2810b49a4cff72aa Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sat, 16 Feb 2002 09:15:07 +0000 Subject: 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). --- Src/hist.c | 38 ++++++++++++++++++++++++-------------- 1 file 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); + } } } -- cgit 1.4.1