aboutsummaryrefslogtreecommitdiff
path: root/src/cuckoocache.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuckoocache.h')
-rw-r--r--src/cuckoocache.h14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/cuckoocache.h b/src/cuckoocache.h
index df320ed465..8370179395 100644
--- a/src/cuckoocache.h
+++ b/src/cuckoocache.h
@@ -14,7 +14,6 @@
#include <cstring>
#include <limits>
#include <memory>
-#include <optional>
#include <utility>
#include <vector>
@@ -360,16 +359,15 @@ public:
* structure
* @returns A pair of the maximum number of elements storable (see setup()
* documentation for more detail) and the approximate total size of these
- * elements in bytes or std::nullopt if the size requested is too large.
+ * elements in bytes.
*/
- std::optional<std::pair<uint32_t, size_t>> setup_bytes(size_t bytes)
+ std::pair<uint32_t, size_t> setup_bytes(size_t bytes)
{
- size_t requested_num_elems = bytes / sizeof(Element);
- if (std::numeric_limits<uint32_t>::max() < requested_num_elems) {
- return std::nullopt;
- }
+ uint32_t requested_num_elems(std::min<size_t>(
+ bytes / sizeof(Element),
+ std::numeric_limits<uint32_t>::max()));
- auto num_elems = setup(bytes/sizeof(Element));
+ auto num_elems = setup(requested_num_elems);
size_t approx_size_bytes = num_elems * sizeof(Element);
return std::make_pair(num_elems, approx_size_bytes);