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

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

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

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

Loading…
Cancel
Save