Add InternalVisibility arena constructor to ExtensionSet

This change adds an arena enabled constructor guarded by `InternalVisibility`. It also moves the existing constructor inline as it's trivial, and implements the default constructor in terms of the (future private) arena constructor.

PiperOrigin-RevId: 547529474
pull/13275/head
Martijn Vels 1 year ago committed by Copybara-Service
parent d6157f7c7e
commit 739a1f8853
  1. 8
      src/google/protobuf/extension_set.cc
  2. 19
      src/google/protobuf/extension_set.h

@ -180,14 +180,6 @@ void ExtensionSet::RegisterMessageExtension(const MessageLite* extendee,
// ===================================================================
// Constructors and basic methods.
ExtensionSet::ExtensionSet(Arena* arena)
: arena_(arena),
flat_capacity_(0),
flat_size_(0),
map_{flat_capacity_ == 0
? nullptr
: Arena::CreateArray<KeyValue>(arena_, flat_capacity_)} {}
ExtensionSet::~ExtensionSet() {
// Deletes all allocated extensions.
if (arena_ == nullptr) {

@ -49,6 +49,7 @@
#include "absl/base/call_once.h"
#include "absl/container/btree_map.h"
#include "absl/log/absl_check.h"
#include "google/protobuf/internal_visibility.h"
#include "google/protobuf/port.h"
#include "google/protobuf/port.h"
#include "google/protobuf/io/coded_stream.h"
@ -194,10 +195,18 @@ class PROTOBUF_EXPORT GeneratedExtensionFinder {
// off to the ExtensionSet for parsing. Etc.
class PROTOBUF_EXPORT ExtensionSet {
public:
constexpr ExtensionSet();
explicit ExtensionSet(Arena* arena);
constexpr ExtensionSet() : ExtensionSet(nullptr) {}
ExtensionSet(const ExtensionSet& rhs) = delete;
// Arena enabled constructors: for internal use only.
ExtensionSet(internal::InternalVisibility, Arena* arena)
: ExtensionSet(arena) {}
// TODO(b/290091828): make constructor private, and migrate `ArenaInitialized`
// to `InternalVisibility` overloaded constructor(s).
explicit constexpr ExtensionSet(Arena* arena);
ExtensionSet(ArenaInitialized, Arena* arena) : ExtensionSet(arena) {}
ExtensionSet(const ExtensionSet&) = delete;
ExtensionSet& operator=(const ExtensionSet&) = delete;
~ExtensionSet();
@ -932,8 +941,8 @@ class PROTOBUF_EXPORT ExtensionSet {
static void DeleteFlatMap(const KeyValue* flat, uint16_t flat_capacity);
};
constexpr ExtensionSet::ExtensionSet()
: arena_(nullptr), flat_capacity_(0), flat_size_(0), map_{nullptr} {}
constexpr ExtensionSet::ExtensionSet(Arena* arena)
: arena_(arena), flat_capacity_(0), flat_size_(0), map_{nullptr} {}
// These are just for convenience...
inline void ExtensionSet::SetString(int number, FieldType type,

Loading…
Cancel
Save