diff --git a/util/options_helper.cc b/util/options_helper.cc index cc7c7594b..c4025631b 100644 --- a/util/options_helper.cc +++ b/util/options_helper.cc @@ -34,23 +34,34 @@ bool isSpecialChar(const char c) { return false; } +namespace { + using + CharMap = std::pair; +} + char UnescapeChar(const char c) { - static const std::unordered_map convert_map = {{'r', '\r'}, - {'n', '\n'}}; + static const CharMap convert_map[] = {{'r', '\r'}, + {'n', '\n'}}; - auto iter = convert_map.find(c); - if (iter == convert_map.end()) { + auto iter = std::find_if(std::begin(convert_map), + std::end(convert_map), + [c](const CharMap& p) { return p.first == c; }); + + if (iter == std::end(convert_map)) { return c; } return iter->second; } char EscapeChar(const char c) { - static const std::unordered_map convert_map = {{'\n', 'n'}, - {'\r', 'r'}}; + static const CharMap convert_map[] = {{'\n', 'n'}, + {'\r', 'r'}}; + + auto iter = std::find_if(std::begin(convert_map), + std::end(convert_map), + [c](const CharMap& p) { return p.first == c; }); - auto iter = convert_map.find(c); - if (iter == convert_map.end()) { + if (iter == std::end(convert_map)) { return c; } return iter->second; diff --git a/util/rate_limiter_test.cc b/util/rate_limiter_test.cc index 43fa5ef45..211aac03a 100644 --- a/util/rate_limiter_test.cc +++ b/util/rate_limiter_test.cc @@ -29,14 +29,14 @@ TEST_F(RateLimiterTest, OverflowRate) { } TEST_F(RateLimiterTest, StartStop) { - std::unique_ptr limiter(new GenericRateLimiter(100, 100, 10)); + std::unique_ptr limiter(NewGenericRateLimiter(100, 100, 10)); } TEST_F(RateLimiterTest, Rate) { auto* env = Env::Default(); struct Arg { Arg(int32_t _target_rate, int _burst) - : limiter(new GenericRateLimiter(_target_rate, 100 * 1000, 10)), + : limiter(NewGenericRateLimiter(_target_rate, 100 * 1000, 10)), request_size(_target_rate / 10), burst(_burst) {} std::unique_ptr limiter;