Don't cache int->string conversion, it doesn't speed up anything.

This commit is contained in:
Andreas Jönsson 2015-05-09 21:23:40 +02:00
parent 4b3fbdd570
commit 83c16755ab
1 changed files with 2 additions and 5 deletions

View File

@ -819,12 +819,9 @@ 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;
std::map<int, generic_string> intToString; // Cache for ints converted to strings.
for (auto it = input.begin(); it != input.end(); ++it) for (auto it = input.begin(); it != input.end(); ++it)
{ {
int converted = stoiStrict(*it); inputAsInts.push_back(stoiStrict(*it));
inputAsInts.push_back(converted);
intToString[converted] = *it;
} }
std::sort(inputAsInts.begin(), inputAsInts.end(), [isDescending](int a, int b) std::sort(inputAsInts.begin(), inputAsInts.end(), [isDescending](int a, int b)
{ {
@ -840,7 +837,7 @@ std::vector<generic_string> numericSort(std::vector<generic_string> input, bool
std::vector<generic_string> output; std::vector<generic_string> output;
for (auto it = inputAsInts.begin(); it != inputAsInts.end(); ++it) for (auto it = inputAsInts.begin(); it != inputAsInts.end(); ++it)
{ {
output.push_back(intToString[*it]); output.push_back(std::to_wstring(*it));
} }
return output; return output;
} }