When sorting, reserve enough space for work + output.
This commit is contained in:
parent
60505765cc
commit
936d9c56fc
|
@ -818,6 +818,7 @@ std::vector<generic_string> numericSort(std::vector<generic_string> input, bool
|
||||||
{
|
{
|
||||||
// Pre-condition: all strings in "input" are convertible to int with stoiStrict.
|
// Pre-condition: all strings in "input" are convertible to int with stoiStrict.
|
||||||
std::vector<int> inputAsInts;
|
std::vector<int> inputAsInts;
|
||||||
|
inputAsInts.reserve(input.size());
|
||||||
for (const generic_string& line : input)
|
for (const generic_string& line : input)
|
||||||
{
|
{
|
||||||
inputAsInts.push_back(stoiStrict(line));
|
inputAsInts.push_back(stoiStrict(line));
|
||||||
|
@ -834,6 +835,7 @@ std::vector<generic_string> numericSort(std::vector<generic_string> input, bool
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
std::vector<generic_string> output;
|
std::vector<generic_string> output;
|
||||||
|
output.reserve(input.size());
|
||||||
for (const int& sortedInt : inputAsInts)
|
for (const int& sortedInt : inputAsInts)
|
||||||
{
|
{
|
||||||
output.push_back(std::to_wstring(sortedInt));
|
output.push_back(std::to_wstring(sortedInt));
|
||||||
|
|
Loading…
Reference in New Issue