Skip to content

Automated Code Change #21711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class FlatAllocatorImpl {
const std::string* AllocateStrings(In&&... in) {
std::string* strings = AllocateArray<std::string>(sizeof...(in));
std::string* res = strings;
Fold({(*strings++ = std::string(std::forward<In>(in)))...});
Fold({(*strings++ = std::forward<In>(in))...});
return res;
}

Expand Down Expand Up @@ -3600,7 +3600,7 @@ class SourceLocationCommentPrinter {
}
}
void AddPostComment(std::string* output) {
if (have_source_loc_ && source_loc_.trailing_comments.size() > 0) {
if (have_source_loc_ && !source_loc_.trailing_comments.empty()) {
absl::StrAppend(output, FormatComment(source_loc_.trailing_comments));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/descriptor_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void SimpleDescriptorDatabase::DescriptorIndex<Value>::FindAllFileNames(

bool SimpleDescriptorDatabase::Add(const FileDescriptorProto& file) {
FileDescriptorProto* new_file = new FileDescriptorProto;
new_file->CopyFrom(file);
*new_file = file;
return AddAndOwn(new_file);
}

Expand Down Expand Up @@ -394,7 +394,7 @@ bool SimpleDescriptorDatabase::MaybeCopy(
const FileDescriptorProto* PROTOBUF_NULLABLE file,
FileDescriptorProto* PROTOBUF_NONNULL output) {
if (file == nullptr) return false;
output->CopyFrom(*file);
*output = *file;
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/google/protobuf/extension_set_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,19 @@ TEST(ExtensionSetTest, CopyFrom) {
unittest::TestAllExtensions message1, message2;

TestUtil::SetAllExtensions(&message1);
message2.CopyFrom(message1);
message2 = message1;
TestUtil::ExpectAllExtensionsSet(message2);
message2.CopyFrom(message1); // exercise copy when fields already exist
message2 = message1; // exercise copy when fields already exist
TestUtil::ExpectAllExtensionsSet(message2);
}

TEST(ExtensionSetTest, CopyFromPacked) {
unittest::TestPackedExtensions message1, message2;

TestUtil::SetPackedExtensions(&message1);
message2.CopyFrom(message1);
message2 = message1;
TestUtil::ExpectPackedExtensionsSet(message2);
message2.CopyFrom(message1); // exercise copy when fields already exist
message2 = message1; // exercise copy when fields already exist
TestUtil::ExpectPackedExtensionsSet(message2);
}

Expand Down Expand Up @@ -810,8 +810,8 @@ TEST(ExtensionSetTest, SpaceUsedExcludingSelf) {
const int base_size = message.SpaceUsedLong();
unittest::ForeignMessage foreign;
foreign.set_c(42);
message.MutableExtension(unittest::optional_foreign_message_extension)
->CopyFrom(foreign);
*message.MutableExtension(unittest::optional_foreign_message_extension) =
foreign;
int min_expected_size = base_size + foreign.SpaceUsedLong();
EXPECT_LE(min_expected_size, message.SpaceUsedLong());
}
Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/generated_message_reflection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ using google::protobuf::internal::ArenaStringPtr;
using google::protobuf::internal::DescriptorTable;
using google::protobuf::internal::ExtensionSet;
using google::protobuf::internal::GenericTypeHandler;
using google::protobuf::internal::GetEmptyString;
using google::protobuf::internal::InlinedStringField;
using google::protobuf::internal::InternalMetadata;
using google::protobuf::internal::LazyField;
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/generated_message_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ bool IsNull(const void* ptr) {

template <>
bool IsNull<WireFormatLite::TYPE_STRING>(const void* ptr) {
return static_cast<const ArenaStringPtr*>(ptr)->Get().size() == 0;
return static_cast<const ArenaStringPtr*>(ptr)->Get().empty();
}

template <>
bool IsNull<WireFormatLite::TYPE_BYTES>(const void* ptr) {
return static_cast<const ArenaStringPtr*>(ptr)->Get().size() == 0;
return static_cast<const ArenaStringPtr*>(ptr)->Get().empty();
}

template <>
Expand Down
2 changes: 0 additions & 2 deletions src/google/protobuf/map_field_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ namespace protobuf {

namespace internal {

using proto2_unittest::TestAllTypes;

struct MapFieldTestPeer {
static auto GetArena(const RepeatedPtrFieldBase& v) { return v.GetArena(); }
template <typename T>
Expand Down
6 changes: 3 additions & 3 deletions src/google/protobuf/map_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2448,11 +2448,11 @@ TEST(GeneratedMapFieldTest, CopyFrom) {
UNITTEST::TestMap message1, message2;

MapTestUtil::SetMapFields(&message1);
message2.CopyFrom(message1);
message2 = message1;
MapTestUtil::ExpectMapFieldsSet(message2);

// Copying from self should be a no-op.
message2.CopyFrom(message2);
message2 = message2;
MapTestUtil::ExpectMapFieldsSet(message2);
}

Expand All @@ -2462,7 +2462,7 @@ TEST(GeneratedMapFieldTest, CopyFromMessageMap) {
(*message1.mutable_map_int32_message())[0].add_repeated_int32(100);
(*message2.mutable_map_int32_message())[0].add_repeated_int32(101);

message1.CopyFrom(message2);
message1 = message2;

// Checks repeated field is overwritten.
EXPECT_EQ(1, message1.map_int32_message().at(0).repeated_int32_size());
Expand Down
4 changes: 0 additions & 4 deletions src/google/protobuf/no_field_presence_map_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ namespace google {
namespace protobuf {
namespace {

using ::proto2_nofieldpresence_unittest::ExplicitForeignMessage;
using ::proto2_nofieldpresence_unittest::FOREIGN_BAZ;
using ::proto2_nofieldpresence_unittest::FOREIGN_FOO;
using ::proto2_nofieldpresence_unittest::ForeignMessage;
using ::proto2_nofieldpresence_unittest::TestAllMapTypes;
using ::testing::Eq;
using ::testing::Gt;
using ::testing::Not;
using ::testing::StrEq;
using ::testing::UnorderedPointwise;

// Custom gmock matchers to simplify testing for map entries.
Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/no_field_presence_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ using ::proto2_nofieldpresence_unittest::TestAllTypes;
using ::testing::Eq;
using ::testing::Gt;
using ::testing::IsEmpty;
using ::testing::Not;
using ::testing::StrEq;
using ::testing::UnorderedPointwise;

Expand Down
Loading