From 5da3ac8f36644de77b2fe63e860a46b8930a04a7 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Mon, 24 Jul 2006 04:53:24 +0000 Subject: [PATCH] Avoid copying TapNote where possible and implement some of these algorithms in terms of NoteData::iterators which take constant time to move to the next element rather than GetTapNote which takes logarithmic time. --- stepmania/src/NoteDataUtil.cpp | 77 ++++++++++++++++------------------ 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/stepmania/src/NoteDataUtil.cpp b/stepmania/src/NoteDataUtil.cpp index 678a6c7f53..6e97f4c7de 100644 --- a/stepmania/src/NoteDataUtil.cpp +++ b/stepmania/src/NoteDataUtil.cpp @@ -133,9 +133,7 @@ static void LoadFromSMNoteDataStringWithPlayer( NoteData& out, const RString &sS } else { - TapNote head_tap = out.GetTapNote( iTrack, iHeadRow ); - head_tap.iDuration = iIndex - iHeadRow; - out.SetTapNote( iTrack, iHeadRow, head_tap ); + out.FindTapNote( iTrack, iHeadRow )->second.iDuration = iIndex - iHeadRow; } /* This won't write tn, but keep parsing normally anyway. */ @@ -574,7 +572,7 @@ void NoteDataUtil::LoadOverlapped( const NoteData &in, NoteData &out, int iNewNu out.SetTapNote( iTrackTo, row, tnFrom ); if( tnFrom.type == TapNote::hold_head ) { - TapNote tnTail = in.GetTapNote( iTrackFrom, iEndIndex ); + const TapNote &tnTail = in.GetTapNote( iTrackFrom, iEndIndex ); out.SetTapNote( iTrackTo, iEndIndex, tnTail ); } } @@ -891,8 +889,9 @@ void NoteDataUtil::RemoveAllButOneTap( NoteData &inout, int row ) for( ; track < inout.GetNumTracks(); ++track ) { - if( inout.GetTapNote(track, row).type == TapNote::tap ) - inout.SetTapNote(track, row, TAP_EMPTY ); + NoteData::iterator iter = inout.FindTapNote( track, row ); + if( iter != inout.end(track) && iter->second.type == TapNote::tap ) + inout.RemoveTapNote( track, iter ); } } @@ -1064,7 +1063,7 @@ static void SuperShuffleTaps( NoteData &inout, int iStartIndex, int iEndIndex ) { for( int t1=0; t1 vTriedTracks; @@ -1097,7 +1094,7 @@ static void SuperShuffleTaps( NoteData &inout, int iStartIndex, int iEndIndex ) if( t1 == t2 ) break; // done swapping - const TapNote tn2 = inout.GetTapNote(t2, r); + const TapNote &tn2 = inout.GetTapNote( t2, r ); switch( tn2.type ) { case TapNote::hold_head: @@ -1114,12 +1111,13 @@ static void SuperShuffleTaps( NoteData &inout, int iStartIndex, int iEndIndex ) } // don't swap into the middle of a hold note - if( inout.IsHoldNoteAtRow(t2,r) ) + if( inout.IsHoldNoteAtRow( t2,r ) ) continue; // do the swap - inout.SetTapNote(t1, r, tn2); - inout.SetTapNote(t2, r, tn1); + const TapNote tnTemp = tn1; + inout.SetTapNote( t1, r, tn2 ); + inout.SetTapNote( t2, r, tnTemp ); break; // done swapping } @@ -1155,15 +1153,15 @@ void NoteDataUtil::Backwards( NoteData &inout ) int iRowEarlier = r; int iRowLater = max_row-r; - TapNote tnEarlier = inout.GetTapNote(t, iRowEarlier); + const TapNote &tnEarlier = inout.GetTapNote( t, iRowEarlier ); if( tnEarlier.type == TapNote::hold_head ) iRowLater -= tnEarlier.iDuration; - out.SetTapNote(t, iRowLater, tnEarlier); + out.SetTapNote( t, iRowLater, tnEarlier ); } } - inout = out; + inout.swap( out ); } void NoteDataUtil::SwapSides( NoteData &inout ) @@ -1750,13 +1748,14 @@ void NoteDataUtil::ClearRight( NoteData &inout ) void NoteDataUtil::CollapseToOne( NoteData &inout ) { FOREACH_NONEMPTY_ROW_ALL_TRACKS( inout, r ) - for( int t=0; tsecond ); + inout.RemoveTapNote( t, iter ); + } } void NoteDataUtil::CollapseLeft( NoteData &inout ) @@ -2017,20 +2016,14 @@ void NoteDataUtil::ScaleRegion( NoteData &nd, float fScale, int iStartIndex, int for( int t=0; tfirst*fScale + iStartIndex ); + temp1.SetTapNote( t, new_row, iter->second ); } } - nd.CopyAll( temp1 ); + nd.swap( temp1 ); } void NoteDataUtil::InsertRows( NoteData &nd, int iStartIndex, int iRowsToAdd ) @@ -2059,10 +2052,12 @@ void NoteDataUtil::RemoveAllTapsOfType( NoteData& ndInOut, TapNote::Type typeToR { for( int t=0; tsecond.type == typeToRemove ) + ndInOut.RemoveTapNote( t, iter++ ); + else + ++iter; } } } @@ -2071,10 +2066,12 @@ void NoteDataUtil::RemoveAllTapsExceptForType( NoteData& ndInOut, TapNote::Type { for( int t=0; tsecond.type != typeToKeep ) + ndInOut.RemoveTapNote( t, iter++ ); + else + ++iter; } } }