diff --git a/cartographer/mapping/probability_values.cc b/cartographer/mapping/probability_values.cc index 9ce7839..5ac9222 100644 --- a/cartographer/mapping/probability_values.cc +++ b/cartographer/mapping/probability_values.cc @@ -42,7 +42,9 @@ std::unique_ptr> PrecomputeValueToBoundedFloat( auto result = absl::make_unique>(); // Repeat two times, so that both values with and without the update marker // can be converted to a probability. - for (int repeat = 0; repeat != 2; ++repeat) { + constexpr int kRepetitionCount = 2; + result->reserve(kRepetitionCount * kNumberOfValues); + for (int repeat = 0; repeat != kRepetitionCount; ++repeat) { for (int value = 0; value != kNumberOfValues; ++value) { result->push_back(SlowValueToBoundedFloat( value, unknown_value, unknown_result, lower_bound, upper_bound)); @@ -73,6 +75,7 @@ const std::vector* const kValueToCorrespondenceCost = std::vector ComputeLookupTableToApplyOdds(const float odds) { std::vector result; + result.reserve(kNumberOfValues); result.push_back(ProbabilityToValue(ProbabilityFromOdds(odds)) + kUpdateMarker); for (int cell = 1; cell != kNumberOfValues; ++cell) { @@ -86,6 +89,7 @@ std::vector ComputeLookupTableToApplyOdds(const float odds) { std::vector ComputeLookupTableToApplyCorrespondenceCostOdds( float odds) { std::vector result; + result.reserve(kNumberOfValues); result.push_back(CorrespondenceCostToValue(ProbabilityToCorrespondenceCost( ProbabilityFromOdds(odds))) + kUpdateMarker);