TiGetClient() excessive use hotspots

This is reducing nearby calls to TiGetClient() API when the value
can be looked up one time and stored in a local variable to make
other decisions about.

This is due to TiGetClient() potentially having a slightly higher
cost to call than previously, this is a kind of peephole
optimization approach (if I can see multiple getters used within
the window it got optmized).

'ticlient' was used for retrieval as ClientData so that future
greps across the codebase for `ti_client` should only match naked
access.
This commit is contained in:
Darryl L. Miles 2025-02-21 17:57:13 +00:00 committed by R. Timothy Edwards
parent 606f37cc80
commit f942ae6e78
4 changed files with 122 additions and 75 deletions

View File

@ -3038,10 +3038,12 @@ extTransFindSubsFunc1(tile, noderecptr)
* regions under the same device)
*/
if (TiGetClient(tile) != extUnInit)
ClientData ticlient = TiGetClient(tile);
if (ticlient != extUnInit)
{
NodeRegion *reg = (NodeRegion *) CD2PTR(ticlient);
if ((noderecptr->region != (NodeRegion *)NULL) &&
(noderecptr->region != TiGetClientPTR(tile)))
(noderecptr->region != reg))
TxError("Warning: Split substrate under device at (%d %d)\n",
tile->ti_ll.p_x, tile->ti_ll.p_y);
if (IsSplit(tile))
@ -3052,7 +3054,7 @@ extTransFindSubsFunc1(tile, noderecptr)
else
type = TiGetTypeExact(tile);
noderecptr->region = (NodeRegion *)TiGetClientPTR(tile);
noderecptr->region = (NodeRegion *) reg;
noderecptr->layer = type;
return 1;
}
@ -4906,14 +4908,15 @@ topside:
len = EDGENULL(&r) ? 0 : r.r_xtop - r.r_xbot;
}
else len = MIN(RIGHT(tile), RIGHT(tp)) - MAX(LEFT(tile), LEFT(tp));
ClientData ticlient = TiGetClient(tp);
if (IsSplit(tp))
{
t = SplitBottomType(tp);
if (TiGetClient(tp) == extUnInit && TTMaskHasType(mask, t))
if (ticlient == extUnInit && TTMaskHasType(mask, t))
{
PUSHTILEBOTTOM(tp, tilePlaneNum);
}
else if (TiGetClientPTR(tp) != reg && TTMaskHasType(mask, t))
else if ((NodeRegion *)CD2PTR(ticlient) != reg && TTMaskHasType(mask, t))
{
/* Count split tile twice, once for each node it belongs to. */
TiSetClient(tp, extUnInit);
@ -4923,7 +4926,7 @@ topside:
else
{
t = TiGetTypeExact(tp);
if (TiGetClient(tp) == extUnInit && TTMaskHasType(mask, t))
if (ticlient == extUnInit && TTMaskHasType(mask, t))
{
PUSHTILE(tp, tilePlaneNum);
}
@ -4951,14 +4954,15 @@ leftside:
len = EDGENULL(&r) ? 0 : r.r_ytop - r.r_ybot;
}
else len = MIN(TOP(tile), TOP(tp)) - MAX(BOTTOM(tile), BOTTOM(tp));
ClientData ticlient = TiGetClient(tp);
if (IsSplit(tp))
{
t = SplitRightType(tp);
if (TiGetClient(tp) == extUnInit && TTMaskHasType(mask, t))
if (ticlient == extUnInit && TTMaskHasType(mask, t))
{
PUSHTILERIGHT(tp, tilePlaneNum);
}
else if (TiGetClientPTR(tp) != reg && TTMaskHasType(mask, t))
else if ((NodeRegion *)CD2PTR(ticlient) != reg && TTMaskHasType(mask, t))
{
/* Count split tile twice, once for each node it belongs to. */
TiSetClient(tp, extUnInit);
@ -4968,7 +4972,7 @@ leftside:
else
{
t = TiGetTypeExact(tp);
if (TiGetClient(tp) == extUnInit && TTMaskHasType(mask, t))
if (ticlient == extUnInit && TTMaskHasType(mask, t))
{
PUSHTILE(tp, tilePlaneNum);
}
@ -4997,14 +5001,15 @@ bottomside:
len = EDGENULL(&r) ? 0 : r.r_xtop - r.r_xbot;
}
else len = MIN(RIGHT(tile), RIGHT(tp)) - MAX(LEFT(tile), LEFT(tp));
ClientData ticlient = TiGetClient(tp);
if (IsSplit(tp))
{
t = SplitTopType(tp);
if (TiGetClient(tp) == extUnInit && TTMaskHasType(mask, t))
if (ticlient == extUnInit && TTMaskHasType(mask, t))
{
PUSHTILETOP(tp, tilePlaneNum);
}
else if (TiGetClientPTR(tp) != reg && TTMaskHasType(mask, t))
else if ((NodeRegion *)CD2PTR(ticlient) != reg && TTMaskHasType(mask, t))
{
/* Count split tile twice, once for each node it belongs to. */
TiSetClient(tp, extUnInit);
@ -5014,7 +5019,7 @@ bottomside:
else
{
t = TiGetTypeExact(tp);
if (TiGetClient(tp) == extUnInit && TTMaskHasType(mask, t))
if (ticlient == extUnInit && TTMaskHasType(mask, t))
{
PUSHTILE(tp, tilePlaneNum);
}
@ -5042,14 +5047,15 @@ rightside:
len = EDGENULL(&r) ? 0 : r.r_ytop - r.r_ybot;
}
else len = MIN(TOP(tile), TOP(tp)) - MAX(BOTTOM(tile), BOTTOM(tp));
ClientData ticlient = TiGetClient(tp);
if (IsSplit(tp))
{
t = SplitLeftType(tp);
if (TiGetClient(tp) == extUnInit && TTMaskHasType(mask, t))
if (ticlient == extUnInit && TTMaskHasType(mask, t))
{
PUSHTILELEFT(tp, tilePlaneNum);
}
else if (TiGetClientPTR(tp) != reg && TTMaskHasType(mask, t))
else if ((NodeRegion *)CD2PTR(ticlient) != reg && TTMaskHasType(mask, t))
{
/* Count split tile twice, once for each node it belongs to */
TiSetClient(tp, extUnInit);
@ -5059,7 +5065,7 @@ rightside:
else
{
t = TiGetTypeExact(tp);
if (TiGetClient(tp) == extUnInit && TTMaskHasType(mask, t))
if (ticlient == extUnInit && TTMaskHasType(mask, t))
{
PUSHTILE(tp, tilePlaneNum);
}

View File

@ -1443,9 +1443,13 @@ FindStartTile(goodies, SourcePoint)
MAX(BOTTOM(tile), BOTTOM(tp))) >> 1;
return(tp);
}
else if (TiGetClient(tp) != CLIENTDEFAULT)
if (((tileJunk *)TiGetClientPTR(tp))->tj_status & RES_TILE_DEV)
else
{
const ClientData ticlient = TiGetClient(tp);
const tileJunk *tj = (tileJunk *)CD2PTR(ticlient);
if (ticlient != CLIENTDEFAULT && tj->tj_status & RES_TILE_DEV)
complex = TRUE;
}
}
/* right */
@ -1460,9 +1464,13 @@ FindStartTile(goodies, SourcePoint)
MAX(BOTTOM(tile), BOTTOM(tp))) >> 1;
return(tp);
}
else if (TiGetClient(tp) != CLIENTDEFAULT)
if (((tileJunk *)TiGetClientPTR(tp))->tj_status & RES_TILE_DEV)
else
{
const ClientData ticlient = TiGetClient(tp);
const tileJunk *tj = (tileJunk *)CD2PTR(ticlient);
if (ticlient != CLIENTDEFAULT && tj->tj_status & RES_TILE_DEV)
complex = TRUE;
}
}
/* top */
@ -1477,9 +1485,13 @@ FindStartTile(goodies, SourcePoint)
MAX(LEFT(tile), LEFT(tp))) >> 1;
return(tp);
}
else if (TiGetClient(tp) != CLIENTDEFAULT)
if (((tileJunk *)TiGetClientPTR(tp))->tj_status & RES_TILE_DEV)
else
{
const ClientData ticlient = TiGetClient(tp);
const tileJunk *tj = (tileJunk *)CD2PTR(ticlient);
if (ticlient != CLIENTDEFAULT && tj->tj_status & RES_TILE_DEV)
complex = TRUE;
}
}
/* bottom */
@ -1494,9 +1506,13 @@ FindStartTile(goodies, SourcePoint)
MAX(LEFT(tile), LEFT(tp))) >> 1;
return(tp);
}
else if (TiGetClient(tp) != CLIENTDEFAULT)
if (((tileJunk *)TiGetClientPTR(tp))->tj_status & RES_TILE_DEV)
else
{
const ClientData ticlient = TiGetClient(tp);
const tileJunk *tj = (tileJunk *)CD2PTR(ticlient);
if (ticlient != CLIENTDEFAULT && tj->tj_status & RES_TILE_DEV)
complex = TRUE;
}
}
if (complex == TRUE)
@ -1529,16 +1545,19 @@ FindStartTile(goodies, SourcePoint)
}
return(tp);
}
else if (TiGetClient(tp) != CLIENTDEFAULT)
else
{
if (((tileJunk *)TiGetClientPTR(tp))->tj_status & RES_TILE_DEV)
const ClientData ticlient = TiGetClient(tp);
if (ticlient != CLIENTDEFAULT)
{
if (!(((tileJunk *)TiGetClientPTR(tp))->tj_status
& RES_TILE_PUSHED))
tileJunk *tj = (tileJunk *)CD2PTR(ticlient);
if (tj->tj_status & RES_TILE_DEV)
{
((tileJunk *)TiGetClientPTR(tp))->tj_status
|= RES_TILE_PUSHED;
STACKPUSH((ClientData)tp, devStack);
if (!(tj->tj_status & RES_TILE_PUSHED))
{
tj->tj_status |= RES_TILE_PUSHED;
STACKPUSH((ClientData)tp, devStack);
}
}
}
}
@ -1560,16 +1579,19 @@ FindStartTile(goodies, SourcePoint)
}
return(tp);
}
else if (TiGetClient(tp) != CLIENTDEFAULT)
else
{
if (((tileJunk *)TiGetClientPTR(tp))->tj_status & RES_TILE_DEV)
const ClientData ticlient = TiGetClient(tp);
if (ticlient != CLIENTDEFAULT)
{
if (!(((tileJunk *)TiGetClientPTR(tp))->tj_status
& RES_TILE_PUSHED))
tileJunk *tj = (tileJunk *)CD2PTR(ticlient);
if (tj->tj_status & RES_TILE_DEV)
{
((tileJunk *)TiGetClientPTR(tp))->tj_status
|= RES_TILE_PUSHED;
STACKPUSH((ClientData)tp, devStack);
if (!(tj->tj_status & RES_TILE_PUSHED))
{
tj->tj_status |= RES_TILE_PUSHED;
STACKPUSH((ClientData)tp, devStack);
}
}
}
}
@ -1591,16 +1613,19 @@ FindStartTile(goodies, SourcePoint)
}
return(tp);
}
else if (TiGetClient(tp) != CLIENTDEFAULT)
else
{
if (((tileJunk *)TiGetClientPTR(tp))->tj_status & RES_TILE_DEV)
const ClientData ticlient = TiGetClient(tp);
if (ticlient != CLIENTDEFAULT)
{
if (!(((tileJunk *)TiGetClientPTR(tp))->tj_status
& RES_TILE_PUSHED))
tileJunk *tj = (tileJunk *)CD2PTR(ticlient);
if (tj->tj_status & RES_TILE_DEV)
{
((tileJunk *)TiGetClientPTR(tp))->tj_status
|= RES_TILE_PUSHED;
STACKPUSH((ClientData)tp, devStack);
if (!(tj->tj_status & RES_TILE_PUSHED))
{
tj->tj_status |= RES_TILE_PUSHED;
STACKPUSH((ClientData)tp, devStack);
}
}
}
}
@ -1622,16 +1647,19 @@ FindStartTile(goodies, SourcePoint)
}
return(tp);
}
else if (TiGetClient(tp) != CLIENTDEFAULT)
else
{
if (((tileJunk *)TiGetClientPTR(tp))->tj_status & RES_TILE_DEV)
const ClientData ticlient = TiGetClient(tp);
if (ticlient != CLIENTDEFAULT)
{
if (!(((tileJunk *)TiGetClientPTR(tp))->tj_status
& RES_TILE_PUSHED))
tileJunk *tj = (tileJunk *)CD2PTR(ticlient);
if (tj->tj_status & RES_TILE_DEV)
{
((tileJunk *)TiGetClientPTR(tp))->tj_status
|= RES_TILE_PUSHED;
STACKPUSH((ClientData)tp, devStack);
if (!(tj->tj_status & RES_TILE_PUSHED))
{
tj->tj_status |= RES_TILE_PUSHED;
STACKPUSH((ClientData)tp, devStack);
}
}
}
}
@ -1718,19 +1746,20 @@ ResGetDevice(pt, type)
tile = ResUse->cu_def->cd_planes[pnum]->pl_hint;
GOTOPOINT(tile, &workingPoint);
const ClientData ticlient = TiGetClient(tile);
if (IsSplit(tile))
{
if (TTMaskHasType(&ExtCurStyle->exts_deviceMask, TiGetLeftType(tile))
|| TTMaskHasType(&ExtCurStyle->exts_deviceMask, TiGetRightType(tile)))
return (((tileJunk *)TiGetClientPTR(tile))->deviceList);
return (((tileJunk *)CD2PTR(ticlient))->deviceList);
}
else if (TTMaskHasType(&ExtCurStyle->exts_deviceMask, TiGetType(tile)))
{
/* Failure to have a valid client data will result in a "Bad Device"
* error and indicates a problem that needs debugging.
*/
if (TiGetClient(tile) != CLIENTDEFAULT)
return (((tileJunk *)TiGetClientPTR(tile))->deviceList);
if (ticlient != CLIENTDEFAULT)
return (((tileJunk *)CD2PTR(ticlient))->deviceList);
}
return NULL;
}

View File

@ -656,10 +656,10 @@ ResRemovePlumbing(tile, arg)
ClientData *arg;
{
if (TiGetClient(tile) != CLIENTDEFAULT)
ClientData ticlient = TiGetClient(tile);
if (ticlient != CLIENTDEFAULT)
{
freeMagic((char *)TiGetClientPTR(tile));
freeMagic((char *)CD2PTR(ticlient));
TiSetClient(tile, CLIENTDEFAULT);
}
return(0);
@ -845,8 +845,9 @@ tileJunk *
resAddField(tile)
Tile *tile;
{
tileJunk *Junk;
if ((Junk = (tileJunk *)TiGetClientPTR(tile)) == (tileJunk *) CLIENTDEFAULT)
ClientData ticlient = TiGetClient(tile);
tileJunk *Junk = (tileJunk *)CD2PTR(ticlient);
if (ticlient == CLIENTDEFAULT)
{
Junk = (tileJunk *) mallocMagic((unsigned) (sizeof(tileJunk)));
ResJunkInit(Junk);

View File

@ -413,9 +413,10 @@ selShortTileProc(tile, ssd)
Tile *tile;
ShortSearchData *ssd;
{
if ((int)TiGetClientINT(tile) < ssd->cost)
const int curr = (int)TiGetClientINT(tile);
if (curr < ssd->cost)
{
ssd->cost = (int)TiGetClientINT(tile);
ssd->cost = curr;
ssd->tile = tile;
}
return 0;
@ -518,10 +519,12 @@ selShortFindReverse(rlist, tile, pnum, fdir)
for (tp = RT(tile); RIGHT(tp) > LEFT(tile); tp = BL(tp))
{
if (TiGetClient(tp) == CLIENTDEFAULT) continue;
if ((int)TiGetClientINT(tp) < mincost)
const ClientData ticlient = TiGetClient(tp);
if (ticlient == CLIENTDEFAULT) continue;
const int curr = (int)CD2INT(ticlient);
if (curr < mincost)
{
mincost = (int)TiGetClientINT(tp);
mincost = curr;
mintp = tp;
mindir = GEO_NORTH;
}
@ -538,10 +541,12 @@ leftside:
for (tp = BL(tile); BOTTOM(tp) < TOP(tile); tp = RT(tp))
{
if (TiGetClient(tp) == CLIENTDEFAULT) continue;
if ((int)TiGetClientINT(tp) < mincost)
const ClientData ticlient = TiGetClient(tp);
if (ticlient == CLIENTDEFAULT) continue;
const int curr = (int)CD2INT(ticlient);
if (curr < mincost)
{
mincost = (int)TiGetClientINT(tp);
mincost = curr;
mintp = tp;
mindir = GEO_WEST;
}
@ -558,10 +563,12 @@ bottomside:
for (tp = LB(tile); LEFT(tp) < RIGHT(tile); tp = TR(tp))
{
if (TiGetClient(tp) == CLIENTDEFAULT) continue;
if ((int)TiGetClientINT(tp) < mincost)
const ClientData ticlient = TiGetClient(tp);
if (ticlient == CLIENTDEFAULT) continue;
const int curr = (int)CD2INT(ticlient);
if (curr < mincost)
{
mincost = (int)TiGetClientINT(tp);
mincost = curr;
mintp = tp;
mindir = GEO_SOUTH;
}
@ -578,10 +585,12 @@ rightside:
for (tp = TR(tile); TOP(tp) > BOTTOM(tile); tp = LB(tp))
{
if (TiGetClient(tp) == CLIENTDEFAULT) continue;
if ((int)TiGetClientINT(tp) < mincost)
const ClientData ticlient = TiGetClient(tp);
if (ticlient == CLIENTDEFAULT) continue;
const int curr = (int)CD2INT(ticlient);
if (curr < mincost)
{
mincost = (int)TiGetClientINT(tp);
mincost = curr;
mintp = tp;
mindir = GEO_EAST;
}
@ -748,9 +757,11 @@ selShortProcessTile(tile, cost, fdir, mask)
/* If this tile is unvisited, or has a lower cost, then return and */
/* keep going. Otherwise, return 1 to stop the search this direction */
if (TiGetClient(tile) == CLIENTDEFAULT)
const ClientData ticlient = TiGetClient(tile);
const int curr = (int)CD2INT(ticlient);
if (ticlient == CLIENTDEFAULT)
TiSetClientINT(tile, cost);
else if ((int)TiGetClientINT(tile) > cost)
else if (curr > cost)
TiSetClientINT(tile, cost);
else
return 1;