Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions smoke/generated/example.protocyte.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,15 +929,15 @@ namespace test::ultimate {
}
}
}
if (values_.size() != 0u && values_.size() != 3u) {
if (!values_.empty() && values_.size() != 3u) {
return ::protocyte::unexpected(::protocyte::ErrorCode::invalid_argument, {},
static_cast<::protocyte::u32>(FieldNumber::values));
}
return {};
}

template<typename Writer>::protocyte::Status serialize(Writer &writer) const noexcept {
if (values_.size() != 0u && values_.size() != 3u) {
if (!values_.empty() && values_.size() != 3u) {
return ::protocyte::unexpected(::protocyte::ErrorCode::invalid_argument, {},
static_cast<::protocyte::u32>(FieldNumber::values));
}
Expand All @@ -952,7 +952,7 @@ namespace test::ultimate {
}

::protocyte::Result<::protocyte::usize> encoded_size() const noexcept {
if (values_.size() != 0u && values_.size() != 3u) {
if (!values_.empty() && values_.size() != 3u) {
return ::protocyte::unexpected(::protocyte::ErrorCode::invalid_argument, {},
static_cast<::protocyte::u32>(FieldNumber::values));
}
Expand Down Expand Up @@ -4254,23 +4254,23 @@ namespace test::ultimate {
}
}
}
if (fixed_integer_array_.size() != 0u && fixed_integer_array_.size() != 3u) {
if (!fixed_integer_array_.empty() && fixed_integer_array_.size() != 3u) {
return ::protocyte::unexpected(::protocyte::ErrorCode::invalid_argument, {},
static_cast<::protocyte::u32>(FieldNumber::fixed_integer_array));
}
if (fixed_repeated_byte_array_.size() != 0u && fixed_repeated_byte_array_.size() != 3u) {
if (!fixed_repeated_byte_array_.empty() && fixed_repeated_byte_array_.size() != 3u) {
return ::protocyte::unexpected(::protocyte::ErrorCode::invalid_argument, {},
static_cast<::protocyte::u32>(FieldNumber::fixed_repeated_byte_array));
}
return {};
}

template<typename Writer>::protocyte::Status serialize(Writer &writer) const noexcept {
if (fixed_integer_array_.size() != 0u && fixed_integer_array_.size() != 3u) {
if (!fixed_integer_array_.empty() && fixed_integer_array_.size() != 3u) {
return ::protocyte::unexpected(::protocyte::ErrorCode::invalid_argument, {},
static_cast<::protocyte::u32>(FieldNumber::fixed_integer_array));
}
if (fixed_repeated_byte_array_.size() != 0u && fixed_repeated_byte_array_.size() != 3u) {
if (!fixed_repeated_byte_array_.empty() && fixed_repeated_byte_array_.size() != 3u) {
return ::protocyte::unexpected(::protocyte::ErrorCode::invalid_argument, {},
static_cast<::protocyte::u32>(FieldNumber::fixed_repeated_byte_array));
}
Expand Down Expand Up @@ -4933,11 +4933,11 @@ namespace test::ultimate {
}

::protocyte::Result<::protocyte::usize> encoded_size() const noexcept {
if (fixed_integer_array_.size() != 0u && fixed_integer_array_.size() != 3u) {
if (!fixed_integer_array_.empty() && fixed_integer_array_.size() != 3u) {
return ::protocyte::unexpected(::protocyte::ErrorCode::invalid_argument, {},
static_cast<::protocyte::u32>(FieldNumber::fixed_integer_array));
}
if (fixed_repeated_byte_array_.size() != 0u && fixed_repeated_byte_array_.size() != 3u) {
if (!fixed_repeated_byte_array_.empty() && fixed_repeated_byte_array_.size() != 3u) {
return ::protocyte::unexpected(::protocyte::ErrorCode::invalid_argument, {},
static_cast<::protocyte::u32>(FieldNumber::fixed_repeated_byte_array));
}
Expand Down
8 changes: 4 additions & 4 deletions smoke/generated/protocyte/runtime/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ namespace protocyte {

template<class T, usize Extent>
constexpr Result<Span<T, Extent>> checked_span_of(const Span<T, Extent> view) noexcept {
if (view.size() != 0u && view.data() == nullptr) {
if (!view.empty() && view.data() == nullptr) {
return protocyte::unexpected(ErrorCode::invalid_argument, {});
}
return view;
Expand Down Expand Up @@ -1462,7 +1462,7 @@ namespace protocyte {
if (!size) {
return protocyte::unexpected(size.error());
}
if (*size != 0u && view.data() == nullptr) {
if (!view.empty() && view.data() == nullptr) {
return protocyte::unexpected(ErrorCode::invalid_argument, {});
}
return Span<const u8> {reinterpret_cast<const u8 *>(view.data()), *size};
Expand Down Expand Up @@ -1570,7 +1570,7 @@ namespace protocyte {
if (lhs.size() != rhs.size()) {
return false;
}
if (!lhs.size()) {
if (lhs.empty()) {
return true;
}
if (::std::is_constant_evaluated()) {
Expand Down Expand Up @@ -3303,7 +3303,7 @@ namespace protocyte {
if (*next_size > max_size()) {
return protocyte::unexpected(ErrorCode::count_limit, {});
}
if (!buckets_.size() || *next_size >= rehash_threshold_for(buckets_.size())) {
if (buckets_.empty() || *next_size >= rehash_threshold_for(buckets_.size())) {
return reserve(*next_size);
}
return {};
Expand Down
18 changes: 9 additions & 9 deletions smoke/src/host_smoke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ namespace {
REQUIRE(moved.has_oneof_bytes());
CHECK(view_equal(moved.oneof_bytes(), view_of(oneof_bytes)));
CHECK(source.special_oneof_case() == Message::Special_oneofCase::none);
CHECK(source.oneof_bytes().size() == 0u);
CHECK(source.oneof_bytes().empty());
}

SECTION("move assignment transfers active message case") {
Expand Down Expand Up @@ -1176,7 +1176,7 @@ namespace {
SECTION("unset fixed bytes stay absent through round trip") {
Message message(ctx);
CHECK_FALSE(message.has_sha256());
CHECK(message.sha256().size() == 0u);
CHECK(message.sha256().empty());
populate_required_fixed_array(message, ctx);

auto encoded_size = message.encoded_size();
Expand All @@ -1191,7 +1191,7 @@ namespace {
protocyte::SliceReader reader(encoded, writer.position());
require_success(parsed.merge_from(reader));
CHECK_FALSE(parsed.has_sha256());
CHECK(parsed.sha256().size() == 0u);
CHECK(parsed.sha256().empty());
}

SECTION("mutable fixed bytes mark presence and zero initialize") {
Expand All @@ -1218,7 +1218,7 @@ namespace {

message.clear_sha256();
CHECK_FALSE(message.has_sha256());
CHECK(message.sha256().size() == 0u);
CHECK(message.sha256().empty());
}

SECTION("explicit zero bytes stay present through round trip") {
Expand Down Expand Up @@ -1376,8 +1376,8 @@ namespace {
CHECK(target_fixed_integer_array[i] == fixed_integer_array_values[i]);
}
CHECK(source.byte_array_size() == 0u);
CHECK(source.integer_array().size() == 0u);
CHECK(source.fixed_integer_array().size() == 0u);
CHECK(source.integer_array().empty());
CHECK(source.fixed_integer_array().empty());
}

SECTION("partially populated fixed arrays are rejected before encoding") {
Expand Down Expand Up @@ -2528,8 +2528,8 @@ TEST_CASE("Protocyte encoding matches protobuf runtime bytes", "[smoke][compat]"
auto parsed = parse_compat_bytes(ctx, compat_cases::unknown_fields);

CHECK(parsed.f_int32() == 321);
CHECK(parsed.map_str_int32().size() == 0u);
CHECK(parsed.map_int32_str().size() == 0u);
CHECK(parsed.map_str_int32().empty());
CHECK(parsed.map_int32_str().empty());
}
}

Expand Down Expand Up @@ -3462,7 +3462,7 @@ TEST_CASE("runtime limits are enforced for mutation and parsing", "[smoke][runti
Message message(ctx);
const auto view = message.mutable_sha256();
CHECK(view.data() == nullptr);
CHECK(view.size() == 0u);
CHECK(view.empty());
}

SECTION("nested message fields respect max_message_bytes") {
Expand Down
2 changes: 1 addition & 1 deletion src/protocyte/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ def _emit_fixed_array_validation(w: CppWriter, message: MessageModel, *, for_siz
continue
if item.repeated:
condition = (
f"{_member(item)}.size() != 0u && "
f"!{_member(item)}.empty() && "
f"{_member(item)}.size() != {_array_max_literal(item)}"
)
else:
Expand Down
8 changes: 4 additions & 4 deletions src/protocyte/runtime/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ namespace protocyte {

template<class T, usize Extent>
constexpr Result<Span<T, Extent>> checked_span_of(const Span<T, Extent> view) noexcept {
if (view.size() != 0u && view.data() == nullptr) {
if (!view.empty() && view.data() == nullptr) {
return protocyte::unexpected(ErrorCode::invalid_argument, {});
}
return view;
Expand Down Expand Up @@ -1462,7 +1462,7 @@ namespace protocyte {
if (!size) {
return protocyte::unexpected(size.error());
}
if (*size != 0u && view.data() == nullptr) {
if (!view.empty() && view.data() == nullptr) {
return protocyte::unexpected(ErrorCode::invalid_argument, {});
}
return Span<const u8> {reinterpret_cast<const u8 *>(view.data()), *size};
Expand Down Expand Up @@ -1570,7 +1570,7 @@ namespace protocyte {
if (lhs.size() != rhs.size()) {
return false;
}
if (!lhs.size()) {
if (lhs.empty()) {
return true;
}
if (::std::is_constant_evaluated()) {
Expand Down Expand Up @@ -3303,7 +3303,7 @@ namespace protocyte {
if (*next_size > max_size()) {
return protocyte::unexpected(ErrorCode::count_limit, {});
}
if (!buckets_.size() || *next_size >= rehash_threshold_for(buckets_.size())) {
if (buckets_.empty() || *next_size >= rehash_threshold_for(buckets_.size())) {
return reserve(*next_size);
}
return {};
Expand Down
13 changes: 7 additions & 6 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_runtime_container_growth_checks_capacity_limits() -> None:
in runtime_header
)
assert "const usize target {count * 2u};" in runtime_header
assert "next_size >= rehash_threshold_for(buckets_.size())" in runtime_header
assert "buckets_.empty() || *next_size >= rehash_threshold_for(buckets_.size())" in runtime_header
assert "static constexpr usize rehash_threshold_for(const usize bucket_count) noexcept" in runtime_header
assert "capacity_ * 2u" not in runtime_header
assert "checked_mul(count, 2u, &target)" not in runtime_header
Expand Down Expand Up @@ -130,7 +130,8 @@ def test_runtime_sequence_containers_accept_spans() -> None:
assert "contiguous_range_size" not in runtime_header
assert "const auto first_addr = reinterpret_cast<uptr>(first);" in runtime_header
assert "const auto last_addr = reinterpret_cast<uptr>(last);" in runtime_header
assert "if (view.size() != 0u && view.data() == nullptr)" in runtime_header
assert "if (!view.empty() && view.data() == nullptr)" in runtime_header
assert "if (view.size() != 0u && view.data() == nullptr)" not in runtime_header
assert "if (*size != 0u && value.data() == nullptr)" in runtime_header
assert "if (last < first)" not in runtime_header
assert "template<class Range> Status assign(const Range &values) noexcept" in vector_body
Expand Down Expand Up @@ -193,7 +194,7 @@ def test_runtime_byte_containers_use_bulk_copy_helpers() -> None:
assert "::std::memmove(dst, src, count);" in runtime_header
assert "::std::memcpy(dst, src, count);" in runtime_header
assert "constexpr bool bytes_equal(const Span<const u8> lhs, const Span<const u8> rhs) noexcept" in runtime_header
assert "if (!lhs.size())" in runtime_header
assert "if (lhs.empty())" in runtime_header
assert "if (::std::is_constant_evaluated())" in runtime_header
assert "return ::std::memcmp(lhs.data(), rhs.data(), lhs.size()) == 0;" in runtime_header
assert "template<usize Max> using ByteArray = Array<u8, Max>;" in runtime_header
Expand Down Expand Up @@ -771,8 +772,8 @@ def test_checked_smoke_output_reflects_copy_propagation() -> None:
assert "if (const auto st = out->copy_from(*this); !st) {" in header
assert "return has_recursive_self() ? recursive_self_.operator->() : nullptr;" in header
assert "static_cast<::protocyte::u32>(FieldNumber::recursive_self), *recursive_self_" in header
assert "fixed_integer_array_.size() != 0u && fixed_integer_array_.size() != 3u" in header
assert "fixed_repeated_byte_array_.size() != 0u && fixed_repeated_byte_array_.size() != 3u" in header
assert "!fixed_integer_array_.empty() && fixed_integer_array_.size() != 3u" in header
assert "!fixed_repeated_byte_array_.empty() && fixed_repeated_byte_array_.size() != 3u" in header
assert (
"for (const auto &packed_value_remote_values : remote_values_) {\n"
" {\n"
Expand Down Expand Up @@ -1108,7 +1109,7 @@ def test_generated_header_emits_constants_and_array_storage() -> None:
assert "return view.status();" in header
assert "if (const auto st = blob_.assign(*view); !st)" in header
assert "if (*len != 32u)" in header
assert "if (values_.size() != 0u && values_.size() != 4u) {" in header
assert "if (!values_.empty() && values_.size() != 4u) {" in header
assert "template<class T, usize Max> struct Array" in runtime_header
assert "template<usize Max> using ByteArray = Array<u8, Max>;" in runtime_header
assert "template<usize Max> struct FixedByteArray" in runtime_header
Expand Down
Loading