aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/map_entry_lite.h
diff options
context:
space:
mode:
authorAdam Cozzette <acozzette@google.com>2017-09-12 10:32:01 -0700
committerAdam Cozzette <acozzette@google.com>2017-09-14 10:03:57 -0700
commit13fd045dbb2b4dacea32be162a41d5a4b0d1802f (patch)
treec219e7eb18b82523e36c6748861c403a14ea66ae /src/google/protobuf/map_entry_lite.h
parentd1bc27caef8377a710370189675cb0958443e8f1 (diff)
downloadprotobuf-13fd045dbb2b4dacea32be162a41d5a4b0d1802f.tar.gz
protobuf-13fd045dbb2b4dacea32be162a41d5a4b0d1802f.tar.bz2
protobuf-13fd045dbb2b4dacea32be162a41d5a4b0d1802f.zip
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/map_entry_lite.h')
-rw-r--r--src/google/protobuf/map_entry_lite.h65
1 files changed, 28 insertions, 37 deletions
diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h
index 0bccf4d2..7f8636a9 100644
--- a/src/google/protobuf/map_entry_lite.h
+++ b/src/google/protobuf/map_entry_lite.h
@@ -36,6 +36,7 @@
#include <google/protobuf/arena.h>
#include <google/protobuf/map.h>
#include <google/protobuf/map_type_handler.h>
+#include <google/protobuf/stubs/port.h>
#include <google/protobuf/wire_format_lite_inl.h>
namespace google {
@@ -132,14 +133,14 @@ class MapEntryImpl : public Base {
static const WireFormatLite::FieldType kEntryValueFieldType = kValueFieldType;
static const int kEntryDefaultEnumValue = default_enum_value;
- MapEntryImpl() : default_instance_(NULL), arena_(NULL) {
+ MapEntryImpl() : arena_(NULL) {
KeyTypeHandler::Initialize(&key_, NULL);
ValueTypeHandler::InitializeMaybeByDefaultEnum(&value_, default_enum_value,
NULL);
_has_bits_[0] = 0;
}
- explicit MapEntryImpl(Arena* arena) : default_instance_(NULL), arena_(arena) {
+ explicit MapEntryImpl(Arena* arena) : arena_(arena) {
KeyTypeHandler::Initialize(&key_, arena);
ValueTypeHandler::InitializeMaybeByDefaultEnum(&value_, default_enum_value,
arena);
@@ -147,11 +148,9 @@ class MapEntryImpl : public Base {
}
~MapEntryImpl() {
- if (this != default_instance_) {
- if (GetArenaNoVirtual() != NULL) return;
- KeyTypeHandler::DeleteNoArena(key_);
- ValueTypeHandler::DeleteNoArena(value_);
- }
+ if (GetArenaNoVirtual() != NULL) return;
+ KeyTypeHandler::DeleteNoArena(key_);
+ ValueTypeHandler::DeleteNoArena(value_);
}
// accessors ======================================================
@@ -160,9 +159,8 @@ class MapEntryImpl : public Base {
return KeyTypeHandler::GetExternalReference(key_);
}
virtual inline const ValueMapEntryAccessorType& value() const {
- GOOGLE_CHECK(default_instance_ != NULL);
- return ValueTypeHandler::DefaultIfNotInitialized(value_,
- default_instance_->value_);
+ return ValueTypeHandler::DefaultIfNotInitialized(
+ value_, Derived::internal_default_instance()->value_);
}
inline KeyMapEntryAccessorType* mutable_key() {
set_has_key();
@@ -265,13 +263,11 @@ class MapEntryImpl : public Base {
Base* New() const {
Derived* entry = new Derived;
- entry->default_instance_ = default_instance_;
return entry;
}
Base* New(Arena* arena) const {
Derived* entry = Arena::CreateMessage<Derived>(arena);
- entry->default_instance_ = default_instance_;
return entry;
}
@@ -309,13 +305,10 @@ class MapEntryImpl : public Base {
clear_has_value();
}
- void set_default_instance(MapEntryImpl* default_instance) {
- default_instance_ = default_instance;
- }
-
- void InitAsDefaultInstance() {
- KeyTypeHandler::AssignDefaultValue(&key_);
- ValueTypeHandler::AssignDefaultValue(&value_);
+ static void InitAsDefaultInstance() {
+ Derived* d = const_cast<Derived*>(Derived::internal_default_instance());
+ KeyTypeHandler::AssignDefaultValue(&d->key_);
+ ValueTypeHandler::AssignDefaultValue(&d->value_);
}
Arena* GetArena() const {
@@ -393,7 +386,7 @@ class MapEntryImpl : public Base {
const Value& value() const { return *value_ptr_; }
private:
- void UseKeyAndValueFromEntry() GOOGLE_ATTRIBUTE_COLD {
+ void UseKeyAndValueFromEntry() GOOGLE_PROTOBUF_ATTRIBUTE_COLD {
// Update key_ in case we need it later (because key() is called).
// This is potentially inefficient, especially if the key is
// expensive to copy (e.g., a long string), but this is a cold
@@ -411,7 +404,7 @@ class MapEntryImpl : public Base {
// into map_, we are not at the end of the input. This is unusual, but
// allowed by the spec.
bool ReadBeyondKeyValuePair(::google::protobuf::io::CodedInputStream* input)
- GOOGLE_ATTRIBUTE_COLD {
+ GOOGLE_PROTOBUF_ATTRIBUTE_COLD {
typedef MoveHelper<KeyTypeHandler::kIsEnum,
KeyTypeHandler::kIsMessage,
KeyTypeHandler::kWireType ==
@@ -517,13 +510,13 @@ class MapEntryImpl : public Base {
return arena_;
}
- MapEntryImpl* default_instance_;
-
+ public: // Needed for constructing tables
KeyOnMemory key_;
ValueOnMemory value_;
Arena* arena_;
uint32 _has_bits_[1];
+ private:
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
@@ -537,23 +530,20 @@ class MapEntryImpl : public Base {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryImpl);
};
-template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType,
+template <typename T, typename Key, typename Value,
+ WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
class MapEntryLite
- : public MapEntryImpl<MapEntryLite<Key, Value, kKeyFieldType,
- kValueFieldType, default_enum_value>,
- MessageLite, Key, Value, kKeyFieldType,
+ : public MapEntryImpl<T, MessageLite, Key, Value, kKeyFieldType,
kValueFieldType, default_enum_value> {
public:
- typedef MapEntryImpl<MapEntryLite, MessageLite, Key, Value, kKeyFieldType,
+ typedef MapEntryImpl<T, MessageLite, Key, Value, kKeyFieldType,
kValueFieldType, default_enum_value>
SuperType;
MapEntryLite() {}
explicit MapEntryLite(Arena* arena) : SuperType(arena) {}
- void MergeFrom(const MapEntryLite<Key, Value, kKeyFieldType, kValueFieldType,
- default_enum_value>& other) {
- MergeFromInternal(other);
- }
+ void MergeFrom(const MapEntryLite& other) { MergeFromInternal(other); }
+
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryLite);
};
@@ -563,9 +553,9 @@ class MapEntryLite
template <typename Derived>
struct DeconstructMapEntry;
-template <typename K, typename V, WireFormatLite::FieldType key,
+template <typename T, typename K, typename V, WireFormatLite::FieldType key,
WireFormatLite::FieldType value, int default_enum>
-struct DeconstructMapEntry<MapEntryLite<K, V, key, value, default_enum> > {
+struct DeconstructMapEntry<MapEntryLite<T, K, V, key, value, default_enum> > {
typedef K Key;
typedef V Value;
static const WireFormatLite::FieldType kKeyFieldType = key;
@@ -636,10 +626,11 @@ struct FromHelper<WireFormatLite::TYPE_MESSAGE> {
template <typename MapEntryType>
struct MapEntryHelper;
-template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType,
+template <typename T, typename Key, typename Value,
+ WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
-struct MapEntryHelper<MapEntryLite<Key, Value, kKeyFieldType, kValueFieldType,
- default_enum_value> > {
+struct MapEntryHelper<MapEntryLite<T, Key, Value, kKeyFieldType,
+ kValueFieldType, default_enum_value> > {
// Provide utilities to parse/serialize key/value. Provide utilities to
// manipulate internal stored type.
typedef MapTypeHandler<kKeyFieldType, Key> KeyTypeHandler;