Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 20, 2023
1 parent d934db0 commit 033629a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/ripple/rpc/handlers/LedgerHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class LedgerHandler

static constexpr char name[] = "ledger";

static constexpr unsigned minApiVer = 1;
static constexpr unsigned minApiVer = RPC::apiMinimumSupportedVersion;

static constexpr unsigned maxApiVer = RPC::apiMaximumValidVersion;

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/handlers/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class VersionHandler

static constexpr char const* name = "version";

static constexpr unsigned minApiVer = 1;
static constexpr unsigned minApiVer = RPC::apiMinimumSupportedVersion;

static constexpr unsigned maxApiVer = RPC::apiMaximumValidVersion;

Expand Down
18 changes: 10 additions & 8 deletions src/ripple/rpc/impl/Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ class HandlerTable
assert(minVer <= maxVer);
assert(maxVer <= RPC::apiMaximumValidVersion);

for (; range.first != range.second; range.first++)
{
if (range.first->second.minApiVer_ <= maxVer &&
range.first->second.maxApiVer_ >= minVer)
return true;
}
return false;
return std::any_of(
range.first,
range.second, //
[minVer, maxVer](auto const& item) {
return item.second.minApiVer_ <= maxVer &&
item.second.maxApiVer_ >= minVer;
});
}

template <std::size_t N>
Expand Down Expand Up @@ -256,7 +256,7 @@ class HandlerTable
auto const range = table_.equal_range(name);
auto const i = std::find_if(
range.first, range.second, [version](auto const& entry) {
return version >= entry.second.minApiVer_ &&
return entry.second.minApiVer_ <= version &&
version <= entry.second.maxApiVer_;
});

Expand All @@ -282,6 +282,8 @@ class HandlerTable
{
static_assert(HandlerImpl::minApiVer <= HandlerImpl::maxApiVer);
static_assert(HandlerImpl::maxApiVer <= RPC::apiMaximumValidVersion);
static_assert(
RPC::apiMinimumSupportedVersion <= HandlerImpl::minApiVer);

if (overlappingApiVersion(
table_.equal_range(HandlerImpl::name),
Expand Down
12 changes: 6 additions & 6 deletions src/test/rpc/Handler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <numeric>
#include <random>

namespace ripple::RPC {
namespace ripple::test {

// NOTE: there should be no need for this function;
// `std::cout << some_duration` should just work if built with a compliant
Expand All @@ -39,7 +39,7 @@ operator<<(std::ostream& os, std::chrono::nanoseconds ns)
return (os << ns.count() << "ns");
}

// NOTE This is a rather naiive effort at a microbenchmark. Ideally we want
// NOTE This is a rather naive effort at a microbenchmark. Ideally we want
// Google Benchmark, or something similar. Also, this actually does not belong
// to unit tests, as it makes little sense to run it in conditions very
// dissimilar to how rippled will normally work.
Expand Down Expand Up @@ -99,7 +99,7 @@ class Handler_test : public beast::unit_test::suite
std::random_device dev;
std::ranlux48 prng(dev());

std::set<const char*> handlerNames = getHandlerNames();
std::set<const char*> handlerNames = RPC::getHandlerNames();
std::vector<const char*> names(
handlerNames.begin(), handlerNames.end());

Expand All @@ -109,7 +109,7 @@ class Handler_test : public beast::unit_test::suite
auto const [mean, stdev, n] = time(
1'000'000,
[&](std::size_t i) {
auto const d = getHandler(1, false, names[i]);
auto const d = RPC::getHandler(1, false, names[i]);
dummy = dummy + i + (int)d->role_;
},
[&]() -> std::size_t { return distr(prng); });
Expand All @@ -128,6 +128,6 @@ class Handler_test : public beast::unit_test::suite
}
};

BEAST_DEFINE_TESTSUITE(Handler, rpc, ripple);
BEAST_DEFINE_TESTSUITE_MANUAL(Handler, test, ripple);

} // namespace ripple::RPC
} // namespace ripple::test

0 comments on commit 033629a

Please sign in to comment.