Keep a temporary State object around instead of allocating and deleting one nearly every time initResultState is called

This commit is contained in:
Michael Votaw
2024-10-05 21:19:47 -05:00
committed by teejusb
parent 46c3442018
commit 9fd4c38efd
2 changed files with 31 additions and 5 deletions
+26 -4
View File
@@ -108,13 +108,36 @@ void StepParityGenerator::addStateToGraph(State * resultState, StepParityNode *
State * StepParityGenerator::initResultState(State * initialState, Row &row, const FootPlacement &columns)
{
State * resultState = new State(row.columnCount);
resultState->columns = columns;
if(tmpState == nullptr)
{
tmpState = new State(row.columnCount);
}
State * resultState = tmpState;
// reset resultState
for(int i = 0; i < NUM_Foot; i++)
{
resultState->whereTheFeetAre[i] = INVALID_COLUMN;
resultState->whatNoteTheFootIsHitting[i] = INVALID_COLUMN;
resultState->didTheFootMove[i] = false;
resultState->isTheFootHolding[i] = false;
}
for (unsigned long i = 0; i < columns.size(); i++)
{
resultState->columns[i] = NONE;
resultState->combinedColumns[i] = NONE;
resultState->movedFeet[i] = NONE;
resultState->holdFeet[i] = NONE;
}
// I tried to condense this, but kept getting the logic messed up
for (unsigned long i = 0; i < columns.size(); i++)
{
resultState->columns[i] = columns[i];
if(columns[i] == NONE) {
continue;
}
@@ -155,12 +178,11 @@ State * StepParityGenerator::initResultState(State * initialState, Row &row, con
if(maybeState != stateCache.end())
{
State* cachedState = maybeState->second;
delete resultState;
return maybeState->second;
}
stateCache.insert({stateHash, resultState});
tmpState = nullptr;
return resultState;
}