From abc4b263a5b058fbecd0d26d9a1098c0df5d6131 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Fri, 31 Dec 2021 22:25:22 -0500 Subject: [PATCH] One additional optimization to the routine just committed, which avoids pushing space tiles and processing them just so it can pop them off the stack and deallocate the memory. --- select/selOps.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/select/selOps.c b/select/selOps.c index 894a71df..a0f0cc64 100644 --- a/select/selOps.c +++ b/select/selOps.c @@ -682,10 +682,19 @@ selShortFindNext(tile, pnum, ldest, mask) else if (!SplitDirection(tile) && fdir == GEO_WEST) goto srchleft; } + /* As a small optimization, check for space tiles and avoid going + * through the hoops of allocating a structure and pushing it on the + * stack. This check is not rigorous, but it saves time for the + * most common case. + */ + for (tp = RT(tile); RIGHT(tp) > LEFT(tile); tp = BL(tp)) { - sd = NewSD(cost + 1, tp, pnum, GEO_NORTH, lmask); - STACKPUSH(sd, ShortStack); + if (TiGetTypeExact(tp) != TT_SPACE) + { + sd = NewSD(cost + 1, tp, pnum, GEO_NORTH, lmask); + STACKPUSH(sd, ShortStack); + } } /* Search left */ @@ -699,8 +708,11 @@ srchleft: for (tp = BL(tile); BOTTOM(tp) < TOP(tile); tp = RT(tp)) { - sd = NewSD(cost + 1, tp, pnum, GEO_WEST, lmask); - STACKPUSH(sd, ShortStack); + if (TiGetTypeExact(tp) != TT_SPACE) + { + sd = NewSD(cost + 1, tp, pnum, GEO_WEST, lmask); + STACKPUSH(sd, ShortStack); + } } /* Search bottom */ @@ -714,8 +726,11 @@ srchbot: for (tp = LB(tile); LEFT(tp) < RIGHT(tile); tp = TR(tp)) { - sd = NewSD(cost + 1, tp, pnum, GEO_SOUTH, lmask); - STACKPUSH(sd, ShortStack); + if (TiGetTypeExact(tp) != TT_SPACE) + { + sd = NewSD(cost + 1, tp, pnum, GEO_SOUTH, lmask); + STACKPUSH(sd, ShortStack); + } } /* Search right */ @@ -729,8 +744,11 @@ srchright: for (tp = TR(tile); TOP(tp) > BOTTOM(tile); tp = LB(tp)) { - sd = NewSD(cost + 1, tp, pnum, GEO_EAST, lmask); - STACKPUSH(sd, ShortStack); + if (TiGetTypeExact(tp) != TT_SPACE) + { + sd = NewSD(cost + 1, tp, pnum, GEO_EAST, lmask); + STACKPUSH(sd, ShortStack); + } } /* Search other connecting planes */ @@ -747,8 +765,11 @@ donesrch: { tp = SelectDef->cd_planes[p]->pl_hint; GOTOPOINT(tp, &tile->ti_ll); - sd = NewSD(cost + 1, tp, p, GEO_CENTER, lmask); - STACKPUSH(sd, ShortStack); + if (TiGetTypeExact(tp) != TT_SPACE) + { + sd = NewSD(cost + 1, tp, p, GEO_CENTER, lmask); + STACKPUSH(sd, ShortStack); + } } } }