assert() is traditionally disabled in release builds, but not in
scylladb. This hasn't caused problems so far, but the latest abseil
release includes a commit [1] that causes a 1000 insn/op regression when
NDEBUG is not defined.
Clearly, we must move towards a build system where NDEBUG is defined in
release builds. But we can't just define it blindly without vetting
all the assert() calls, as some were written with the expectation that
they are enabled in release mode.
To solve the conundrum, change all assert() calls to a new SCYLLA_ASSERT()
macro in utils/assert.hh. This macro is always defined and is not conditional
on NDEBUG, so we can later (after vetting Seastar) enable NDEBUG in release
mode.
[1] 66ef711d68
Closes scylladb/scylladb#20006
46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
/*
|
|
* Copyright (C) 2017-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "utils/assert.hh"
|
|
#include "interval.hh"
|
|
#include <seastar/core/print.hh>
|
|
|
|
#include "seastarx.hh"
|
|
|
|
using int_range = interval<int>;
|
|
|
|
inline
|
|
unsigned cardinality(const int_range& r) {
|
|
SCYLLA_ASSERT(r.start());
|
|
SCYLLA_ASSERT(r.end());
|
|
return r.end()->value() - r.start()->value() + r.start()->is_inclusive() + r.end()->is_inclusive() - 1;
|
|
}
|
|
|
|
inline
|
|
unsigned cardinality(const std::optional<int_range>& ropt) {
|
|
return ropt ? cardinality(*ropt) : 0;
|
|
}
|
|
|
|
inline
|
|
std::optional<int_range> intersection(const int_range& a, const int_range& b) {
|
|
auto int_tri_cmp = [] (int x, int y) {
|
|
return x <=> y;
|
|
};
|
|
return a.intersection(b, int_tri_cmp);
|
|
}
|
|
|
|
inline
|
|
int_range make_int_range(int start_inclusive, int end_exclusive) {
|
|
if (end_exclusive <= start_inclusive) {
|
|
throw std::runtime_error(format("invalid range: [{:d}, {:d})", start_inclusive, end_exclusive));
|
|
}
|
|
return int_range({start_inclusive}, {end_exclusive - 1});
|
|
}
|