From 6e6808008e57fe9f11ebcc56a3e771f3e14d3c53 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 18 Jun 2006 00:36:58 +0000 Subject: [PATCH] Simplify. (This changes it from a cubic time operation to a quadratic. Also handles the case where a comment begins on the last line and that line isn't terminated with a newline.) --- stepmania/src/NoteDataUtil.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/stepmania/src/NoteDataUtil.cpp b/stepmania/src/NoteDataUtil.cpp index a4473364e3..8d5432c31b 100644 --- a/stepmania/src/NoteDataUtil.cpp +++ b/stepmania/src/NoteDataUtil.cpp @@ -57,15 +57,14 @@ void NoteDataUtil::LoadFromSMNoteDataString( NoteData &out, RString sSMNoteData out.Init(); out.SetNumTracks( iNumTracks ); - // strip comments out of sSMNoteData - while( sSMNoteData.find("//") != string::npos ) { - size_t iIndexCommentStart = sSMNoteData.find("//"); - size_t iIndexCommentEnd = sSMNoteData.find("\n", iIndexCommentStart); - if( iIndexCommentEnd == string::npos ) // comment doesn't have an end? - sSMNoteData.erase( iIndexCommentStart, 2 ); - else - sSMNoteData.erase( iIndexCommentStart, iIndexCommentEnd-iIndexCommentStart ); + RString::size_type iIndexCommentStart = 0; + + while( (iIndexCommentStart = sSMNoteData.find("//", iIndexCommentStart)) != RString::npos ) + { + RString::size_type iIndexCommentEnd = sSMNoteData.find( "\n", iIndexCommentStart ); + sSMNoteData.erase( iIndexCommentStart, iIndexCommentEnd - iIndexCommentStart ); + } } vector asMeasures;