Skip to content

Commit

Permalink
Minor cleanup: IWYU, etc.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 597698437
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 12, 2024
1 parent d14dbbc commit cdcd166
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
33 changes: 18 additions & 15 deletions src/google/protobuf/generated_message_reflection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
#include <atomic>
#include <cstdint>
#include <cstring>
#include <new> // IWYU pragma: keep for operator delete
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#include "absl/base/attributes.h"
#include "absl/base/call_once.h"
#include "absl/base/casts.h"
#include "absl/container/flat_hash_map.h"
#include "absl/base/const_init.h"
#include "absl/container/flat_hash_set.h"
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/strings/match.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
Expand All @@ -37,10 +39,11 @@
#include "google/protobuf/generated_message_util.h"
#include "google/protobuf/inlined_string_field.h"
#include "google/protobuf/map_field.h"
#include "google/protobuf/map_field_inl.h"
#include "google/protobuf/message.h"
#include "google/protobuf/message_lite.h"
#include "google/protobuf/raw_ptr.h"
#include "google/protobuf/repeated_field.h"
#include "google/protobuf/repeated_ptr_field.h"
#include "google/protobuf/unknown_field_set.h"


Expand Down Expand Up @@ -636,7 +639,7 @@ void SwapFieldHelper::SwapInlinedStrings(const Reflection* r, Message* lhs,
auto* lhs_string = r->MutableRaw<InlinedStringField>(lhs, field);
auto* rhs_string = r->MutableRaw<InlinedStringField>(rhs, field);
uint32_t index = r->schema_.InlinedStringIndex(field);
ABSL_DCHECK_GT(index, 0);
ABSL_DCHECK_GT(index, 0u);
uint32_t* lhs_array = r->MutableInlinedStringDonatedArray(lhs);
uint32_t* rhs_array = r->MutableInlinedStringDonatedArray(rhs);
uint32_t* lhs_state = &lhs_array[index / 32];
Expand Down Expand Up @@ -1889,7 +1892,7 @@ void Reflection::SetString(Message* message, const FieldDescriptor* field,
case FieldOptions::STRING: {
if (IsInlined(field)) {
const uint32_t index = schema_.InlinedStringIndex(field);
ABSL_DCHECK_GT(index, 0);
ABSL_DCHECK_GT(index, 0u);
uint32_t* states =
&MutableInlinedStringDonatedArray(message)[index / 32];
uint32_t mask = ~(static_cast<uint32_t>(1) << (index % 32));
Expand Down Expand Up @@ -1950,7 +1953,7 @@ void Reflection::SetString(Message* message, const FieldDescriptor* field,
if (IsInlined(field)) {
auto* str = MutableField<InlinedStringField>(message, field);
const uint32_t index = schema_.InlinedStringIndex(field);
ABSL_DCHECK_GT(index, 0);
ABSL_DCHECK_GT(index, 0u);
uint32_t* states =
&MutableInlinedStringDonatedArray(message)[index / 32];
uint32_t mask = ~(static_cast<uint32_t>(1) << (index % 32));
Expand Down Expand Up @@ -2791,7 +2794,7 @@ uint32_t* Reflection::MutableInlinedStringDonatedArray(Message* message) const {
bool Reflection::IsInlinedStringDonated(const Message& message,
const FieldDescriptor* field) const {
uint32_t index = schema_.InlinedStringIndex(field);
ABSL_DCHECK_GT(index, 0);
ABSL_DCHECK_GT(index, 0u);
return IsIndexInHasBitSet(GetInlinedStringDonatedArray(message), index);
}

Expand Down Expand Up @@ -2824,7 +2827,7 @@ void Reflection::SwapInlinedStringDonated(Message* lhs, Message* rhs,
ABSL_CHECK_EQ(rhs_array[0] & 0x1u, 0u);
// Swap donation status bit.
uint32_t index = schema_.InlinedStringIndex(field);
ABSL_DCHECK_GT(index, 0);
ABSL_DCHECK_GT(index, 0u);
if (rhs_donated) {
SetInlinedStringDonated(index, lhs_array);
ClearInlinedStringDonated(index, rhs_array);
Expand Down Expand Up @@ -3580,17 +3583,17 @@ namespace {
// all the allocated reflection instances.
struct MetadataOwner {
~MetadataOwner() {
for (auto range : metadata_arrays_) {
for (auto range : metadata_arrays) {
for (const Metadata* m = range.first; m < range.second; m++) {
delete m->reflection;
}
}
}

void AddArray(const Metadata* begin, const Metadata* end) {
mu_.Lock();
metadata_arrays_.push_back(std::make_pair(begin, end));
mu_.Unlock();
mu.Lock();
metadata_arrays.push_back(std::make_pair(begin, end));
mu.Unlock();
}

static MetadataOwner* Instance() {
Expand All @@ -3601,8 +3604,8 @@ struct MetadataOwner {
private:
MetadataOwner() = default; // private because singleton

absl::Mutex mu_;
std::vector<std::pair<const Metadata*, const Metadata*> > metadata_arrays_;
absl::Mutex mu;
std::vector<std::pair<const Metadata*, const Metadata*>> metadata_arrays;
};

void AssignDescriptorsImpl(const DescriptorTable* table, bool eager) {
Expand Down
6 changes: 3 additions & 3 deletions src/google/protobuf/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,13 +921,13 @@ class PROTOBUF_EXPORT Reflection final {
// of field->message_type() (if message_type != nullptr).
// We use 2 routine rather than 4 (const vs mutable) x (scalar vs pointer).
void* MutableRawRepeatedField(Message* message, const FieldDescriptor* field,
FieldDescriptor::CppType, int ctype,
const Descriptor* message_type) const;
FieldDescriptor::CppType cpptype, int ctype,
const Descriptor* desc) const;

const void* GetRawRepeatedField(const Message& message,
const FieldDescriptor* field,
FieldDescriptor::CppType cpptype, int ctype,
const Descriptor* message_type) const;
const Descriptor* desc) const;

// The following methods are used to implement (Mutable)RepeatedFieldRef.
// A Ref object will store a raw pointer to the repeated field data (obtained
Expand Down

0 comments on commit cdcd166

Please sign in to comment.