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 * StepParityGenerator::initResultState(State * initialState, Row &row, const FootPlacement &columns)
|
||||||
{
|
{
|
||||||
State * resultState = new State(row.columnCount);
|
if(tmpState == nullptr)
|
||||||
resultState->columns = columns;
|
{
|
||||||
|
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
|
// I tried to condense this, but kept getting the logic messed up
|
||||||
for (unsigned long i = 0; i < columns.size(); i++)
|
for (unsigned long i = 0; i < columns.size(); i++)
|
||||||
{
|
{
|
||||||
|
resultState->columns[i] = columns[i];
|
||||||
if(columns[i] == NONE) {
|
if(columns[i] == NONE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -155,12 +178,11 @@ State * StepParityGenerator::initResultState(State * initialState, Row &row, con
|
|||||||
if(maybeState != stateCache.end())
|
if(maybeState != stateCache.end())
|
||||||
{
|
{
|
||||||
State* cachedState = maybeState->second;
|
State* cachedState = maybeState->second;
|
||||||
delete resultState;
|
|
||||||
return maybeState->second;
|
return maybeState->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
stateCache.insert({stateHash, resultState});
|
stateCache.insert({stateHash, resultState});
|
||||||
|
tmpState = nullptr;
|
||||||
return resultState;
|
return resultState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace StepParity {
|
|||||||
StepParity::StepParityNode * startNode = nullptr;
|
StepParity::StepParityNode * startNode = nullptr;
|
||||||
StepParity::State * endingState = nullptr;
|
StepParity::State * endingState = nullptr;
|
||||||
StepParity::StepParityNode * endNode = nullptr;
|
StepParity::StepParityNode * endNode = nullptr;
|
||||||
|
StepParity::State * tmpState = nullptr;
|
||||||
public:
|
public:
|
||||||
std::unordered_map <std::uint64_t, StepParity::State*> stateCache;
|
std::unordered_map <std::uint64_t, StepParity::State*> stateCache;
|
||||||
std::vector<StepParity::StepParityNode*> nodes;
|
std::vector<StepParity::StepParityNode*> nodes;
|
||||||
@@ -72,6 +72,10 @@ namespace StepParity {
|
|||||||
{
|
{
|
||||||
delete endingState;
|
delete endingState;
|
||||||
}
|
}
|
||||||
|
if(tmpState != nullptr)
|
||||||
|
{
|
||||||
|
delete tmpState;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// @brief Analyzes the given NoteData to generate a vector of StepParity::Rows, with each step annotated with
|
/// @brief Analyzes the given NoteData to generate a vector of StepParity::Rows, with each step annotated with
|
||||||
/// a foot placement.
|
/// a foot placement.
|
||||||
|
|||||||
Reference in New Issue
Block a user