cache StepsID::ToSteps to speed up html writing
This commit is contained in:
@@ -339,6 +339,8 @@ void Song::RevertFromDisk( bool bAllowNotesLoss )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StepsID::FlushCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -154,21 +154,31 @@ void StepsID::FromSteps( const Steps *p )
|
|||||||
* them back out (which we don't do except in the editor), it won't be permanent.
|
* them back out (which we don't do except in the editor), it won't be permanent.
|
||||||
* We could do this during the actual Steps::GetID() call, instead, but then it'd have
|
* We could do this during the actual Steps::GetID() call, instead, but then it'd have
|
||||||
* to have access to Song::m_LoadedFromProfile. */
|
* to have access to Song::m_LoadedFromProfile. */
|
||||||
|
|
||||||
|
static map<StepsID,Steps *> g_StepsIDCache;
|
||||||
Steps *StepsID::ToSteps( const Song *p, bool bAllowNull ) const
|
Steps *StepsID::ToSteps( const Song *p, bool bAllowNull ) const
|
||||||
{
|
{
|
||||||
if( st == STEPS_TYPE_INVALID || dc == DIFFICULTY_INVALID )
|
if( st == STEPS_TYPE_INVALID || dc == DIFFICULTY_INVALID )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
map<StepsID,Steps *>::iterator it = g_StepsIDCache.find( *this );
|
||||||
|
if( it != g_StepsIDCache.end() )
|
||||||
|
return it->second;
|
||||||
|
|
||||||
vector<Steps*> vNotes;
|
vector<Steps*> vNotes;
|
||||||
if( dc == DIFFICULTY_EDIT )
|
if( dc == DIFFICULTY_EDIT )
|
||||||
p->GetSteps( vNotes, st, dc, -1, -1, sDescription, true );
|
p->GetSteps( vNotes, st, dc, -1, -1, sDescription, true, 1 );
|
||||||
else
|
else
|
||||||
p->GetSteps( vNotes, st, dc, -1, -1, "", true );
|
p->GetSteps( vNotes, st, dc, -1, -1, "", true, 1 );
|
||||||
|
|
||||||
|
Steps *ret = NULL;
|
||||||
if( !vNotes.empty() )
|
if( !vNotes.empty() )
|
||||||
return vNotes[0];
|
ret = vNotes[0];
|
||||||
if( bAllowNull )
|
else if( !bAllowNull )
|
||||||
return NULL;
|
|
||||||
RageException::Throw( "%i, %i, \"%s\"", st, dc, sDescription.c_str() );
|
RageException::Throw( "%i, %i, \"%s\"", st, dc, sDescription.c_str() );
|
||||||
|
|
||||||
|
g_StepsIDCache[*this] = ret;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
XNode* StepsID::CreateNode() const
|
XNode* StepsID::CreateNode() const
|
||||||
@@ -187,6 +197,12 @@ XNode* StepsID::CreateNode() const
|
|||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void StepsID::FlushCache()
|
||||||
|
{
|
||||||
|
g_StepsIDCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void StepsID::LoadFromNode( const XNode* pNode )
|
void StepsID::LoadFromNode( const XNode* pNode )
|
||||||
{
|
{
|
||||||
ASSERT( pNode->name == "Steps" );
|
ASSERT( pNode->name == "Steps" );
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public:
|
|||||||
void LoadFromNode( const XNode* pNode );
|
void LoadFromNode( const XNode* pNode );
|
||||||
CString ToString() const;
|
CString ToString() const;
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
static void FlushCache();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user