IWYU & other minor NFC changes in repeated_*_field.*

PiperOrigin-RevId: 671554520
pull/17977/head
Protobuf Team Bot 5 months ago committed by Copybara-Service
parent 76794bf3ad
commit eacaa2bacc
  1. 7
      src/google/protobuf/repeated_field.h
  2. 2
      src/google/protobuf/repeated_field_unittest.cc
  3. 2
      src/google/protobuf/repeated_ptr_field.cc
  4. 39
      src/google/protobuf/repeated_ptr_field.h

@ -28,7 +28,6 @@
#include <iterator> #include <iterator>
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <string>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
@ -36,7 +35,6 @@
#include "absl/base/dynamic_annotations.h" #include "absl/base/dynamic_annotations.h"
#include "absl/base/optimization.h" #include "absl/base/optimization.h"
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/meta/type_traits.h" #include "absl/meta/type_traits.h"
#include "absl/strings/cord.h" #include "absl/strings/cord.h"
#include "google/protobuf/arena.h" #include "google/protobuf/arena.h"
@ -46,7 +44,6 @@
#include "google/protobuf/port.h" #include "google/protobuf/port.h"
#include "google/protobuf/repeated_ptr_field.h" #include "google/protobuf/repeated_ptr_field.h"
// Must be included last. // Must be included last.
#include "google/protobuf/port_def.inc" #include "google/protobuf/port_def.inc"
@ -79,7 +76,11 @@ constexpr int RepeatedFieldLowerClampLimit() {
// overflows when multiplied by 2 (which is undefined behavior). Sizes above // overflows when multiplied by 2 (which is undefined behavior). Sizes above
// this will clamp to the maximum int value instead of following exponential // this will clamp to the maximum int value instead of following exponential
// growth when growing a repeated field. // growth when growing a repeated field.
#if defined(__cpp_inline_variables)
inline constexpr int kRepeatedFieldUpperClampLimit =
#else
constexpr int kRepeatedFieldUpperClampLimit = constexpr int kRepeatedFieldUpperClampLimit =
#endif
(std::numeric_limits<int>::max() / 2) + 1; (std::numeric_limits<int>::max() / 2) + 1;
template <typename Element> template <typename Element>

@ -24,6 +24,7 @@
#include <limits> #include <limits>
#include <list> #include <list>
#include <memory> #include <memory>
#include <new>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
@ -34,7 +35,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"
#include "absl/numeric/bits.h" #include "absl/numeric/bits.h"
#include "absl/random/random.h"
#include "absl/strings/cord.h" #include "absl/strings/cord.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/types/span.h" #include "absl/types/span.h"

@ -16,9 +16,9 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <limits> #include <limits>
#include <new>
#include <string> #include <string>
#include "absl/base/prefetch.h"
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"
#include "google/protobuf/arena.h" #include "google/protobuf/arena.h"
#include "google/protobuf/message_lite.h" #include "google/protobuf/message_lite.h"

@ -26,8 +26,8 @@
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
#include <limits> #include <limits>
#include <new>
#include <string> #include <string>
#include <tuple>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
@ -40,7 +40,6 @@
#include "google/protobuf/message_lite.h" #include "google/protobuf/message_lite.h"
#include "google/protobuf/port.h" #include "google/protobuf/port.h"
// Must be included last. // Must be included last.
#include "google/protobuf/port_def.inc" #include "google/protobuf/port_def.inc"
@ -92,7 +91,7 @@ struct IsMovable
// Do not use this struct - it exists for internal use only. // Do not use this struct - it exists for internal use only.
template <typename T> template <typename T>
struct ArenaOffsetHelper { struct ArenaOffsetHelper {
constexpr static size_t value = offsetof(T, arena_); static constexpr size_t value = offsetof(T, arena_);
}; };
// This is the common base class for RepeatedPtrFields. It deals only in void* // This is the common base class for RepeatedPtrFields. It deals only in void*
@ -102,11 +101,16 @@ struct ArenaOffsetHelper {
// but may have a template argument called TypeHandler. Its signature is: // but may have a template argument called TypeHandler. Its signature is:
// class TypeHandler { // class TypeHandler {
// public: // public:
// typedef MyType Type; // using Type = MyType;
// static Type* New(); // using Movable = ...;
// static Type* NewFromPrototype(const Type* prototype, //
// Arena* arena); // static Type*(*)(Arena*) GetNewFunc();
// static void Delete(Type*); // static void GetArena(Type* value);
//
// static Type* New(Arena* arena);
// static Type* New(Arena* arena, Type&& value);
// static Type* NewFromPrototype(const Type* prototype, Arena* arena);
// static void Delete(Type*, Arena* arena);
// static void Clear(Type*); // static void Clear(Type*);
// static void Merge(const Type& from, Type* to); // static void Merge(const Type& from, Type* to);
// //
@ -145,7 +149,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
~RepeatedPtrFieldBase() { ~RepeatedPtrFieldBase() {
#ifndef NDEBUG #ifndef NDEBUG
// Try to trigger segfault / asan failure in non-opt builds. If arena_ // Try to trigger segfault / asan failure in non-opt builds if arena_
// lifetime has ended before the destructor. // lifetime has ended before the destructor.
if (arena_) (void)arena_->SpaceAllocated(); if (arena_) (void)arena_->SpaceAllocated();
#endif #endif
@ -318,9 +322,9 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
template <typename TypeHandler> template <typename TypeHandler>
void CopyFrom(const RepeatedPtrFieldBase& other) { void CopyFrom(const RepeatedPtrFieldBase& other) {
if (&other == this) return; if (&other == this) return;
RepeatedPtrFieldBase::Clear<TypeHandler>(); Clear<TypeHandler>();
if (other.empty()) return; if (other.empty()) return;
RepeatedPtrFieldBase::MergeFrom<typename TypeHandler::Type>(other); MergeFrom<typename TypeHandler::Type>(other);
} }
void CloseGap(int start, int num); void CloseGap(int start, int num);
@ -808,10 +812,13 @@ PROTOBUF_EXPORT void InternalOutOfLineDeleteMessageLite(MessageLite* message);
template <typename GenericType> template <typename GenericType>
class GenericTypeHandler { class GenericTypeHandler {
public: public:
typedef GenericType Type; using Type = GenericType;
using Movable = IsMovable<GenericType>; using Movable = IsMovable<GenericType>;
static constexpr auto GetNewFunc() { return Arena::DefaultConstruct<Type>; } static constexpr auto GetNewFunc() { return Arena::DefaultConstruct<Type>; }
static inline Arena* GetArena(GenericType* value) {
return Arena::InternalGetArena(value);
}
static inline GenericType* New(Arena* arena) { static inline GenericType* New(Arena* arena) {
return static_cast<GenericType*>(Arena::DefaultConstruct<Type>(arena)); return static_cast<GenericType*>(Arena::DefaultConstruct<Type>(arena));
@ -837,10 +844,6 @@ class GenericTypeHandler {
delete value; delete value;
#endif #endif
} }
static inline Arena* GetArena(GenericType* value) {
return Arena::InternalGetArena(value);
}
static inline void Clear(GenericType* value) { value->Clear(); } static inline void Clear(GenericType* value) { value->Clear(); }
static void Merge(const GenericType& from, GenericType* to); static void Merge(const GenericType& from, GenericType* to);
static inline size_t SpaceUsedLong(const GenericType& value) { static inline size_t SpaceUsedLong(const GenericType& value) {
@ -887,10 +890,11 @@ PROTOBUF_EXPORT void* NewStringElement(Arena* arena);
template <> template <>
class GenericTypeHandler<std::string> { class GenericTypeHandler<std::string> {
public: public:
typedef std::string Type; using Type = std::string;
using Movable = IsMovable<Type>; using Movable = IsMovable<Type>;
static constexpr auto GetNewFunc() { return NewStringElement; } static constexpr auto GetNewFunc() { return NewStringElement; }
static inline Arena* GetArena(std::string*) { return nullptr; }
static PROTOBUF_NOINLINE std::string* New(Arena* arena) { static PROTOBUF_NOINLINE std::string* New(Arena* arena) {
return Arena::Create<std::string>(arena); return Arena::Create<std::string>(arena);
@ -902,7 +906,6 @@ class GenericTypeHandler<std::string> {
Arena* arena) { Arena* arena) {
return New(arena); return New(arena);
} }
static inline Arena* GetArena(std::string*) { return nullptr; }
static inline void Delete(std::string* value, Arena* arena) { static inline void Delete(std::string* value, Arena* arena) {
if (arena == nullptr) { if (arena == nullptr) {
delete value; delete value;

Loading…
Cancel
Save