diff options
Diffstat (limited to 'src/google/protobuf/map_entry_lite.h')
-rw-r--r-- | src/google/protobuf/map_entry_lite.h | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index 7c477c56..01c734bc 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -33,7 +33,9 @@ #include <assert.h> +#include <google/protobuf/stubs/casts.h> #include <google/protobuf/arena.h> +#include <google/protobuf/arenastring.h> #include <google/protobuf/map.h> #include <google/protobuf/map_type_handler.h> #include <google/protobuf/stubs/port.h> @@ -175,13 +177,13 @@ class MapEntryImpl : public Base { // MapEntryImpl is for implementation only and this function isn't called // anywhere. Just provide a fake implementation here for MessageLite. - string GetTypeName() const { return ""; } + string GetTypeName() const override { return ""; } - void CheckTypeAndMergeFrom(const MessageLite& other) { + void CheckTypeAndMergeFrom(const MessageLite& other) override { MergeFromInternal(*::google::protobuf::down_cast<const Derived*>(&other)); } - bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* input) { + bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* input) override { uint32 tag; for (;;) { @@ -200,8 +202,7 @@ class MapEntryImpl : public Base { return false; } set_has_key(); - if (!input->ExpectTag(kValueTag)) break; - GOOGLE_FALLTHROUGH_INTENDED; + break; case kValueTag: if (!ValueTypeHandler::Read(input, mutable_value())) { @@ -223,7 +224,7 @@ class MapEntryImpl : public Base { } } - size_t ByteSizeLong() const { + size_t ByteSizeLong() const override { size_t size = 0; size += has_key() ? kTagSize + static_cast<size_t>(KeyTypeHandler::ByteSize(key())) : 0; @@ -232,13 +233,13 @@ class MapEntryImpl : public Base { return size; } - void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream* output) const { + void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream* output) const override { KeyTypeHandler::Write(kKeyFieldNumber, key(), output); ValueTypeHandler::Write(kValueFieldNumber, value(), output); } ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(bool deterministic, - ::google::protobuf::uint8* output) const { + ::google::protobuf::uint8* output) const override { output = KeyTypeHandler::InternalWriteToArray(kKeyFieldNumber, key(), deterministic, output); output = ValueTypeHandler::InternalWriteToArray(kValueFieldNumber, value(), @@ -248,7 +249,7 @@ class MapEntryImpl : public Base { // Don't override SerializeWithCachedSizesToArray. Use MessageLite's. - int GetCachedSize() const { + int GetCachedSize() const override { int size = 0; size += has_key() ? static_cast<int>(kTagSize) + KeyTypeHandler::GetCachedSize(key()) @@ -259,25 +260,18 @@ class MapEntryImpl : public Base { return size; } - bool IsInitialized() const { return ValueTypeHandler::IsInitialized(value_); } + bool IsInitialized() const override { return ValueTypeHandler::IsInitialized(value_); } - Base* New() const { + Base* New() const override { Derived* entry = new Derived; return entry; } - Base* New(Arena* arena) const { + Base* New(Arena* arena) const override { Derived* entry = Arena::CreateMessage<Derived>(arena); return entry; } - size_t SpaceUsedLong() const { - size_t size = sizeof(Derived); - size += KeyTypeHandler::SpaceUsedInMapEntryLong(key_); - size += ValueTypeHandler::SpaceUsedInMapEntryLong(value_); - return size; - } - protected: // We can't declare this function directly here as it would hide the other // overload (const Message&). @@ -297,7 +291,7 @@ class MapEntryImpl : public Base { } public: - void Clear() { + void Clear() override { KeyTypeHandler::Clear(&key_, GetArenaNoVirtual()); ValueTypeHandler::ClearMaybeByDefaultEnum( &value_, GetArenaNoVirtual(), default_enum_value); @@ -311,7 +305,7 @@ class MapEntryImpl : public Base { ValueTypeHandler::AssignDefaultValue(&d->value_); } - Arena* GetArena() const { + Arena* GetArena() const override { return GetArenaNoVirtual(); } @@ -354,9 +348,9 @@ class MapEntryImpl : public Base { // We could use memcmp here, but we don't bother. The tag is one byte. GOOGLE_COMPILE_ASSERT(kTagSize == 1, tag_size_error); if (size > 0 && *reinterpret_cast<const char*>(data) == kValueTag) { - typename Map::size_type size = map_->size(); + typename Map::size_type map_size = map_->size(); value_ptr_ = &(*map_)[key_]; - if (GOOGLE_PREDICT_TRUE(size != map_->size())) { + if (GOOGLE_PREDICT_TRUE(map_size != map_->size())) { // We created a new key-value pair. Fill in the value. typedef typename MapIf<ValueTypeHandler::kIsEnum, int*, Value*>::type T; @@ -431,7 +425,7 @@ class MapEntryImpl : public Base { Value* value_ptr_; // On the fast path entry_ is not used. And, when entry_ is used, it's set // to mf_->NewEntry(), so in the arena case we must call entry_.release. - google::protobuf::scoped_ptr<MapEntryImpl> entry_; + std::unique_ptr<MapEntryImpl> entry_; }; protected: @@ -465,8 +459,8 @@ class MapEntryImpl : public Base { BaseClass::set_has_key(); BaseClass::set_has_value(); } - inline const KeyMapEntryAccessorType& key() const { return key_; } - inline const ValueMapEntryAccessorType& value() const { return value_; } + inline const KeyMapEntryAccessorType &key() const override { return key_; } + inline const ValueMapEntryAccessorType& value() const override { return value_; } private: const Key& key_; @@ -603,7 +597,9 @@ template <> struct FromHelper<WireFormatLite::TYPE_STRING> { static ArenaStringPtr From(const string& x) { ArenaStringPtr res; - *res.UnsafeRawStringPointer() = const_cast<string*>(&x); + TaggedPtr<::std::string> ptr; + ptr.Set(const_cast<string*>(&x)); + res.UnsafeSetTaggedPointer(ptr); return res; } }; @@ -611,7 +607,9 @@ template <> struct FromHelper<WireFormatLite::TYPE_BYTES> { static ArenaStringPtr From(const string& x) { ArenaStringPtr res; - *res.UnsafeRawStringPointer() = const_cast<string*>(&x); + TaggedPtr<::std::string> ptr; + ptr.Set(const_cast<string*>(&x)); + res.UnsafeSetTaggedPointer(ptr); return res; } }; |