Skip to content

Commit

Permalink
Style: use is_nonzero() vs. !is_zero().
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed May 24, 2024
1 parent f8e8239 commit 52cee87
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions include/bitcoin/database/impl/primitives/head.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ size_t CLASS::buckets() const NOEXCEPT
TEMPLATE
Link CLASS::index(const Key& key) const NOEXCEPT
{
BC_ASSERT_MSG(!is_zero(buckets_), "hash table requires buckets");
BC_ASSERT_MSG(is_nonzero(buckets_), "hash table requires buckets");

// TODO: for greater flexibility, inject hash function through template.
if constexpr (Hash)
Expand All @@ -65,7 +65,7 @@ Link CLASS::index(const Key& key) const NOEXCEPT
TEMPLATE
bool CLASS::create() NOEXCEPT
{
if (!is_zero(file_.size()))
if (is_nonzero(file_.size()))
return false;

const auto allocation = size();
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/database/impl/primitives/manager.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ constexpr size_t CLASS::link_to_position(const Link& link) NOEXCEPT
// Slab implies link/key incorporated into size.
return value;
}
else if constexpr (!is_zero(array_count<Key>))
else if constexpr (is_nonzero(array_count<Key>))
{
// Record implies link/key independent of Size.
constexpr auto element_size = Link::size + array_count<Key> + Size;
Expand Down Expand Up @@ -156,7 +156,7 @@ constexpr Link CLASS::position_to_link(size_t position) NOEXCEPT
// Slab implies link/key incorporated into size.
return { cast_link(position) };
}
else if constexpr (!is_zero(array_count<Key>))
else if constexpr (is_nonzero(array_count<Key>))
{
// Record implies link/key independent of Size.
constexpr auto element_size = Link::size + array_count<Key> + Size;
Expand All @@ -165,7 +165,7 @@ constexpr Link CLASS::position_to_link(size_t position) NOEXCEPT
else
{
// No key implies no linked list.
static_assert(!is_zero(Size));
static_assert(is_nonzero(Size));
return { cast_link(position / Size) };
}
}
Expand Down
12 changes: 6 additions & 6 deletions include/bitcoin/database/impl/query/initialize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@ namespace database {
TEMPLATE
inline bool CLASS::is_initialized() const NOEXCEPT
{
return !is_zero(store_.confirmed.count()) &&
!is_zero(store_.candidate.count());
return is_nonzero(store_.confirmed.count()) &&
is_nonzero(store_.candidate.count());
}
TEMPLATE
inline size_t CLASS::get_top_candidate() const NOEXCEPT
{
BC_ASSERT_MSG(!is_zero(store_.candidate.count()), "empty");
BC_ASSERT_MSG(is_nonzero(store_.candidate.count()), "empty");
return sub1(store_.candidate.count());
}

TEMPLATE
inline size_t CLASS::get_top_confirmed() const NOEXCEPT
{
BC_ASSERT_MSG(!is_zero(store_.confirmed.count()), "empty");
BC_ASSERT_MSG(is_nonzero(store_.confirmed.count()), "empty");
return sub1(store_.confirmed.count());
}


TEMPLATE
size_t CLASS::get_fork() const NOEXCEPT
{
for (auto height = get_top_confirmed(); !is_zero(height); --height)
for (auto height = get_top_confirmed(); is_nonzero(height); --height)
if (to_confirmed(height) == to_candidate(height))
return height;

Expand Down Expand Up @@ -104,7 +104,7 @@ associations CLASS::get_unassociated_above(size_t height,
associations out{};
const auto top = std::min(get_top_candidate(), last);

while (++height <= top && !is_zero(count))
while (++height <= top && is_nonzero(count))
{
if (get_unassociated(item, to_candidate(height)))
{
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/tables/archives/txs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct txs
{
const auto count = source.read_little_endian<tx::integer, schema::count_>();
source.skip_bytes(schema::bit + bytes::size);
if (!is_zero(count))
if (is_nonzero(count))
{
coinbase_fk = source.read_little_endian<tx::integer, tx::size>();
return source;
Expand Down
2 changes: 1 addition & 1 deletion src/file/rotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ BC_POP_WARNING()
// Always write it all, since it's a circular buffer.
const auto written = count;

while (!is_zero(count))
while (is_nonzero(count))
{
if (is_zero(remaining_) && !rotate())
throw ostream_exception{ "rotate" };
Expand Down
4 changes: 2 additions & 2 deletions test/file/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(file_utilities__space__file__true)

size_t out{};
BOOST_REQUIRE(file::space(out, TEST_PATH));
BOOST_WARN(!is_zero(out));
BOOST_WARN(is_nonzero(out));
}

BOOST_AUTO_TEST_CASE(file_utilities__space__create_directory__true)
Expand All @@ -361,7 +361,7 @@ BOOST_AUTO_TEST_CASE(file_utilities__space__create_directory__true)

size_t out{};
BOOST_REQUIRE(file::space(out, directory));
BOOST_WARN(!is_zero(out));
BOOST_WARN(is_nonzero(out));
}

BOOST_AUTO_TEST_SUITE_END()
4 changes: 2 additions & 2 deletions test/memory/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ BOOST_AUTO_TEST_SUITE(memory_utilities_tests)
// test should never fail on any platform, though an API failure returns zero.
BOOST_AUTO_TEST_CASE(memory_utilities__page_size__always__non_zero)
{
BOOST_REQUIRE_NE(page_size(), zero);
BOOST_REQUIRE(is_nonzero(page_size()));
}

// It is not possible for the actual memory to be zero and an overflow will
// return max_uint64, so this test should never fail on any platform, though
// an API failure returns zero.
BOOST_AUTO_TEST_CASE(memory_utilities__system_memory__always__nonzero)
{
BOOST_REQUIRE(!is_zero(system_memory()));
BOOST_REQUIRE(is_nonzero(system_memory()));
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 1 addition & 1 deletion test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ std::string read_line(const std::filesystem::path& file_path,
{
std::string out{};
std::ifstream file(system::to_extended_path(file_path));
do { out.clear(); std::getline(file, out); } while (!is_zero(line--));
do { out.clear(); std::getline(file, out); } while (is_nonzero(line--));
return out;
}

Expand Down

0 comments on commit 52cee87

Please sign in to comment.