pre-initialize size of vectors for writing nps/notes per measure to cache file.

This commit is contained in:
Michael Votaw
2025-03-03 21:24:17 -08:00
committed by teejusb
parent c0db6beb9c
commit 239d38d5aa
2 changed files with 4 additions and 2 deletions
+2 -2
View File
@@ -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. // The vast majority of charts don't, so there's no reason to store duplicated data.
const std::vector<std::vector<float>> &allNpsPerMeasures = in.GetAllNpsPerMeasures(); const std::vector<std::vector<float>> &allNpsPerMeasures = in.GetAllNpsPerMeasures();
std::vector<RString> npsPerMeasureStrings; std::vector<RString> npsPerMeasureStrings;
npsPerMeasureStrings.reserve(allNpsPerMeasures.size());
for(std::vector<float> npsPerMeasure : allNpsPerMeasures) for(std::vector<float> npsPerMeasure : allNpsPerMeasures)
{ {
npsPerMeasureStrings.push_back(serialize(npsPerMeasure, ",", 3)); npsPerMeasureStrings.push_back(serialize(npsPerMeasure, ",", 3));
@@ -457,7 +457,7 @@ static RString GetSSCNoteData( const Song &song, const Steps &in, bool bSavingCa
const std::vector<std::vector<int>> &allNotesPerMeasures = in.GetAllNotesPerMeasures(); const std::vector<std::vector<int>> &allNotesPerMeasures = in.GetAllNotesPerMeasures();
std::vector<RString> notesPerMeasureStrings; std::vector<RString> notesPerMeasureStrings;
notesPerMeasureStrings.reserve(allNotesPerMeasures.size());
for(std::vector<int> notesPerMeasure : allNotesPerMeasures) for(std::vector<int> notesPerMeasure : allNotesPerMeasures)
{ {
notesPerMeasureStrings.push_back(serialize(notesPerMeasure, ",")); notesPerMeasureStrings.push_back(serialize(notesPerMeasure, ","));
+2
View File
@@ -724,6 +724,7 @@ RString join( const RString &sDelimitor, std::vector<RString>::const_iterator be
RString serialize(const std::vector<float> & sSource, const RString &sDelimitor, int precision) RString serialize(const std::vector<float> & sSource, const RString &sDelimitor, int precision)
{ {
std::vector<RString> values; std::vector<RString> values;
values.reserve(sSource.size());
RString precisionStr = ssprintf("%%.%df", precision); RString precisionStr = ssprintf("%%.%df", precision);
for(float s : sSource) for(float s : sSource)
{ {
@@ -735,6 +736,7 @@ RString serialize(const std::vector<float> & sSource, const RString &sDelimitor,
RString serialize(const std::vector<int> & sSource, const RString &sDelimitor) RString serialize(const std::vector<int> & sSource, const RString &sDelimitor)
{ {
std::vector<RString> values; std::vector<RString> values;
values.reserve(sSource.size());
for(int s : sSource) for(int s : sSource)
{ {
values.push_back(ssprintf("%d", s)); values.push_back(ssprintf("%d", s));