From 239d38d5aa4f16a0b3bfeb64fe767a83fb31b1ca Mon Sep 17 00:00:00 2001 From: Michael Votaw Date: Mon, 3 Mar 2025 18:09:07 -0600 Subject: [PATCH] pre-initialize size of vectors for writing nps/notes per measure to cache file. --- src/NotesWriterSSC.cpp | 4 ++-- src/RageUtil.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/NotesWriterSSC.cpp b/src/NotesWriterSSC.cpp index 799f790afb..a0a7d1958b 100644 --- a/src/NotesWriterSSC.cpp +++ b/src/NotesWriterSSC.cpp @@ -447,7 +447,7 @@ static RString GetSSCNoteData( const Song &song, const Steps &in, bool bSavingCa // The vast majority of charts don't, so there's no reason to store duplicated data. const std::vector> &allNpsPerMeasures = in.GetAllNpsPerMeasures(); std::vector npsPerMeasureStrings; - + npsPerMeasureStrings.reserve(allNpsPerMeasures.size()); for(std::vector npsPerMeasure : allNpsPerMeasures) { npsPerMeasureStrings.push_back(serialize(npsPerMeasure, ",", 3)); @@ -457,7 +457,7 @@ static RString GetSSCNoteData( const Song &song, const Steps &in, bool bSavingCa const std::vector> &allNotesPerMeasures = in.GetAllNotesPerMeasures(); std::vector notesPerMeasureStrings; - + notesPerMeasureStrings.reserve(allNotesPerMeasures.size()); for(std::vector notesPerMeasure : allNotesPerMeasures) { notesPerMeasureStrings.push_back(serialize(notesPerMeasure, ",")); diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index e1bd5ab2fc..8ea0df6622 100644 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -724,6 +724,7 @@ RString join( const RString &sDelimitor, std::vector::const_iterator be RString serialize(const std::vector & sSource, const RString &sDelimitor, int precision) { std::vector values; + values.reserve(sSource.size()); RString precisionStr = ssprintf("%%.%df", precision); for(float s : sSource) { @@ -735,6 +736,7 @@ RString serialize(const std::vector & sSource, const RString &sDelimitor, RString serialize(const std::vector & sSource, const RString &sDelimitor) { std::vector values; + values.reserve(sSource.size()); for(int s : sSource) { values.push_back(ssprintf("%d", s));