diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 4b9b7f48e7..2e4479c50b 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -339,6 +339,8 @@ void Song::RevertFromDisk( bool bAllowNotesLoss ) } } } + + StepsID::FlushCache(); } diff --git a/stepmania/src/StepsUtil.cpp b/stepmania/src/StepsUtil.cpp index 5ed09436bd..6237dcc8d6 100644 --- a/stepmania/src/StepsUtil.cpp +++ b/stepmania/src/StepsUtil.cpp @@ -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. * We could do this during the actual Steps::GetID() call, instead, but then it'd have * to have access to Song::m_LoadedFromProfile. */ + +static map g_StepsIDCache; Steps *StepsID::ToSteps( const Song *p, bool bAllowNull ) const { if( st == STEPS_TYPE_INVALID || dc == DIFFICULTY_INVALID ) return NULL; + map::iterator it = g_StepsIDCache.find( *this ); + if( it != g_StepsIDCache.end() ) + return it->second; + vector vNotes; if( dc == DIFFICULTY_EDIT ) - p->GetSteps( vNotes, st, dc, -1, -1, sDescription, true ); + p->GetSteps( vNotes, st, dc, -1, -1, sDescription, true, 1 ); else - p->GetSteps( vNotes, st, dc, -1, -1, "", true ); + p->GetSteps( vNotes, st, dc, -1, -1, "", true, 1 ); + + Steps *ret = NULL; if( !vNotes.empty() ) - return vNotes[0]; - if( bAllowNull ) - return NULL; - RageException::Throw( "%i, %i, \"%s\"", st, dc, sDescription.c_str() ); + ret = vNotes[0]; + else if( !bAllowNull ) + RageException::Throw( "%i, %i, \"%s\"", st, dc, sDescription.c_str() ); + + g_StepsIDCache[*this] = ret; + return ret; } XNode* StepsID::CreateNode() const @@ -187,6 +197,12 @@ XNode* StepsID::CreateNode() const return pNode; } + +void StepsID::FlushCache() +{ + g_StepsIDCache.clear(); +} + void StepsID::LoadFromNode( const XNode* pNode ) { ASSERT( pNode->name == "Steps" ); diff --git a/stepmania/src/StepsUtil.h b/stepmania/src/StepsUtil.h index 9d6635d762..96fae4b985 100644 --- a/stepmania/src/StepsUtil.h +++ b/stepmania/src/StepsUtil.h @@ -51,6 +51,7 @@ public: void LoadFromNode( const XNode* pNode ); CString ToString() const; bool IsValid() const; + static void FlushCache(); }; #endif