Small nits (#1280)
* Create rate limiter using factory function in the test. * Convert function local statics in option helper to a C array that does not perform dynamic memory allocation. This is helpful when you try to memory isolate different DB instances.
This commit is contained in:
parent
2a2ebb6f5e
commit
3981345be1
@ -34,23 +34,34 @@ bool isSpecialChar(const char c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char UnescapeChar(const char c) {
|
||||
static const std::unordered_map<char, char> convert_map = {{'r', '\r'},
|
||||
{'n', '\n'}};
|
||||
namespace {
|
||||
using
|
||||
CharMap = std::pair<char, char>;
|
||||
}
|
||||
|
||||
auto iter = convert_map.find(c);
|
||||
if (iter == convert_map.end()) {
|
||||
char UnescapeChar(const char c) {
|
||||
static const CharMap convert_map[] = {{'r', '\r'},
|
||||
{'n', '\n'}};
|
||||
|
||||
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<char, char> convert_map = {{'\n', 'n'},
|
||||
{'\r', 'r'}};
|
||||
static const CharMap convert_map[] = {{'\n', 'n'},
|
||||
{'\r', 'r'}};
|
||||
|
||||
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;
|
||||
|
@ -29,14 +29,14 @@ TEST_F(RateLimiterTest, OverflowRate) {
|
||||
}
|
||||
|
||||
TEST_F(RateLimiterTest, StartStop) {
|
||||
std::unique_ptr<RateLimiter> limiter(new GenericRateLimiter(100, 100, 10));
|
||||
std::unique_ptr<RateLimiter> 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<RateLimiter> limiter;
|
||||
|
Loading…
Reference in New Issue
Block a user