From 9bb49366257b5673a4b1672a9fff7fc970417001 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 10 Oct 2019 13:33:43 -0700 Subject: [PATCH] modules/client: Minor upgrades to std::clamp/std::minmax templates. --- modules/client/keys/claim.cc | 14 +++++++------- modules/client/keys/query.cc | 14 +++++++------- modules/client/rooms/context.cc | 7 +++---- modules/client/sync.cc | 18 ++++++++---------- .../client/sync/rooms/unread_notifications.cc | 4 ++-- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/modules/client/keys/claim.cc b/modules/client/keys/claim.cc index 84cbffec5..87cd9e934 100644 --- a/modules/client/keys/claim.cc +++ b/modules/client/keys/claim.cc @@ -122,14 +122,14 @@ m::resource::response post__keys_claim(client &client, const m::resource::request &request) { - const milliseconds timeout{[&request] + const milliseconds + timeout_min{claim_timeout_min}, + timeout_max{claim_timeout_max}, + timeout_default{claim_timeout_default}, + timeout { - const milliseconds _default(claim_timeout_default); - milliseconds ret(request.get("timeout", _default)); - ret = std::max(ret, milliseconds(claim_timeout_min)); - ret = std::min(ret, milliseconds(claim_timeout_max)); - return ret; - }()}; + std::clamp(request.get("timeout", timeout_default), timeout_min, timeout_max) + }; const json::object &one_time_keys { diff --git a/modules/client/keys/query.cc b/modules/client/keys/query.cc index 0ae4649d9..b42d213b9 100644 --- a/modules/client/keys/query.cc +++ b/modules/client/keys/query.cc @@ -121,14 +121,14 @@ m::resource::response post__keys_query(client &client, const m::resource::request &request) { - const milliseconds timeout{[&request] + const milliseconds + timeout_min{query_timeout_min}, + timeout_max{query_timeout_max}, + timeout_default{query_timeout_default}, + timeout { - const milliseconds _default(query_timeout_default); - milliseconds ret(request.get("timeout", _default)); - ret = std::max(ret, milliseconds(query_timeout_min)); - ret = std::min(ret, milliseconds(query_timeout_max)); - return ret; - }()}; + std::clamp(request.get("timeout", timeout_default), timeout_min, timeout_max) + }; const auto &token { diff --git a/modules/client/rooms/context.cc b/modules/client/rooms/context.cc index 0caaeda09..6e1feab84 100644 --- a/modules/client/rooms/context.cc +++ b/modules/client/rooms/context.cc @@ -63,11 +63,10 @@ get__context(client &client, url::decode(event_id, request.parv[2]) }; - const auto limit{[&request] + const auto &limit { - auto ret(request.query.get("limit", default_limit)); - return std::min(ret, size_t(limit_max)); - }()}; + std::min(request.query.get("limit", default_limit), size_t(limit_max)) + }; const m::room room { diff --git a/modules/client/sync.cc b/modules/client/sync.cc index a03b0cf64..1d64f14e4 100644 --- a/modules/client/sync.cc +++ b/modules/client/sync.cc @@ -1106,17 +1106,15 @@ try { uint64_t(lex_cast(next_batch_token?: "-1"_sv)) } -,timesout{[&request] +,timesout { - auto ret - { - request.query.get("timeout", milliseconds(timeout_default)) - }; - - ret = std::min(ret, milliseconds(timeout_max)); - ret = std::max(ret, milliseconds(timeout_min)); - return now() + ret; -}()} + std::clamp + ( + request.query.get("timeout", milliseconds(timeout_default)), + milliseconds(timeout_min), + milliseconds(timeout_max) + ) +} ,full_state { request.query.get("full_state", false) diff --git a/modules/client/sync/rooms/unread_notifications.cc b/modules/client/sync/rooms/unread_notifications.cc index e094f118c..ff2389dbe 100644 --- a/modules/client/sync/rooms/unread_notifications.cc +++ b/modules/client/sync/rooms/unread_notifications.cc @@ -204,7 +204,7 @@ ircd::m::sync::_notification_count(const room &room, { const event::idx_range range { - std::min(a, b), std::max(a, b) + std::minmax(a, b) }; return room::events::count(room, range); @@ -223,7 +223,7 @@ ircd::m::sync::_highlight_count(const room &room, const event::idx_range range { - std::min(a, b), std::max(a, b) + std::minmax(a, b) }; return highlight.count_between(room, range);