From 540965cb40363e39b668b170735d29a0e20ebecd Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Wed, 23 Aug 2006 20:42:26 +0000 Subject: [PATCH] Don't compute the compressed string or the hash unless it is required. --- stepmania/src/Steps.cpp | 22 +++++++++++++++++++--- stepmania/src/Steps.h | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/stepmania/src/Steps.cpp b/stepmania/src/Steps.cpp index 527a6bb11b..8cb348151e 100644 --- a/stepmania/src/Steps.cpp +++ b/stepmania/src/Steps.cpp @@ -45,6 +45,22 @@ Steps::~Steps() { } +unsigned Steps::GetHash() const +{ + if( parent ) + return parent->GetHash(); + if( m_uHash ) + return m_uHash; + if( m_sNoteDataCompressed.empty() ) + { + if( !m_bNoteDataIsFilled ) + return 0; // No data, no hash. + NoteDataUtil::GetSMNoteDataString( *m_pNoteData, m_sNoteDataCompressed ); + } + m_uHash = GetHashForString( m_sNoteDataCompressed ); + return m_uHash; +} + void Steps::SetNoteData( const NoteData& noteDataNew ) { ASSERT( noteDataNew.GetNumTracks() == GameManager::StepsTypeToNumTracks(m_StepsType) ); @@ -61,8 +77,8 @@ void Steps::SetNoteData( const NoteData& noteDataNew ) *m_pNoteData = noteDataNew; m_bNoteDataIsFilled = true; - NoteDataUtil::GetSMNoteDataString( *m_pNoteData, m_sNoteDataCompressed ); - m_uHash = GetHashForString( m_sNoteDataCompressed ); + m_sNoteDataCompressed = EMPTY_STRING; + m_uHash = 0; m_sFilename = EMPTY_STRING; // We can no longer read from the file because it has changed in memory. } @@ -87,7 +103,7 @@ void Steps::SetSMNoteData( const RString ¬es_comp_ ) m_bNoteDataIsFilled = false; m_sNoteDataCompressed = notes_comp_; - m_uHash = GetHashForString( m_sNoteDataCompressed ); + m_uHash = 0; m_sFilename = EMPTY_STRING; // We can no longer read from the file because it has changed in memory. } diff --git a/stepmania/src/Steps.h b/stepmania/src/Steps.h index 541fe0ad0e..216751ccb8 100644 --- a/stepmania/src/Steps.h +++ b/stepmania/src/Steps.h @@ -36,7 +36,6 @@ public: bool IsAPlayerEdit() const { return IsAnEdit() && GetLoadedFromProfileSlot() < ProfileSlot_Machine; } bool WasLoadedFromProfile() const { return m_LoadedFromProfile != ProfileSlot_INVALID; } ProfileSlot GetLoadedFromProfileSlot() const { return m_LoadedFromProfile; } - unsigned GetHash() const { return Real()->m_uHash; } RString GetDescription() const { return Real()->m_sDescription; } Difficulty GetDifficulty() const { return Real()->m_Difficulty; } int GetMeter() const { return Real()->m_iMeter; } @@ -56,6 +55,7 @@ public: void SetCachedRadarValues( const RadarValues v[NUM_PLAYERS] ); float PredictMeter() const; + unsigned GetHash() const; void GetNoteData( NoteData& noteDataOut ) const; void SetNoteData( const NoteData& noteDataNew ); void SetSMNoteData( const RString ¬es_comp ); @@ -87,7 +87,7 @@ private: ProfileSlot m_LoadedFromProfile; // ProfileSlot_INVALID if wasn't loaded from a profile /* These values are pulled from the autogen source first, if there is one. */ - unsigned m_uHash; // only used if m_Difficulty == DIFFICULTY_EDIT + mutable unsigned m_uHash; // only used if m_Difficulty == DIFFICULTY_EDIT RString m_sDescription; // Step author, edit name, or something meaningful Difficulty m_Difficulty; // difficulty classification int m_iMeter; // difficulty rating from MIN_METER to MAX_METER