When sorting, reserve enough space for work + output.

This commit is contained in:
Andreas Jönsson 2015-05-10 10:30:17 +02:00
parent 60505765cc
commit 936d9c56fc
1 changed files with 2 additions and 0 deletions

View File

@ -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.
std::vector<int> inputAsInts;
inputAsInts.reserve(input.size());
for (const generic_string& line : input)
{
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;
output.reserve(input.size());
for (const int& sortedInt : inputAsInts)
{
output.push_back(std::to_wstring(sortedInt));