Keep a temporary State object around instead of allocating and deleting one nearly every time initResultState is called
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace StepParity {
|
||||
StepParity::StepParityNode * startNode = nullptr;
|
||||
StepParity::State * endingState = nullptr;
|
||||
StepParity::StepParityNode * endNode = nullptr;
|
||||
|
||||
StepParity::State * tmpState = nullptr;
|
||||
public:
|
||||
std::unordered_map <std::uint64_t, StepParity::State*> stateCache;
|
||||
std::vector<StepParity::StepParityNode*> nodes;
|
||||
@@ -72,6 +72,10 @@ namespace StepParity {
|
||||
{
|
||||
delete endingState;
|
||||
}
|
||||
if(tmpState != nullptr)
|
||||
{
|
||||
delete tmpState;
|
||||
}
|
||||
}
|
||||
/// @brief Analyzes the given NoteData to generate a vector of StepParity::Rows, with each step annotated with
|
||||
/// a foot placement.
|
||||
|
||||
Reference in New Issue
Block a user