aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/repeated_field.h
diff options
context:
space:
mode:
authorGravatar Bo Yang <teboring@google.com>2015-05-21 14:28:59 -0700
committerGravatar Bo Yang <teboring@google.com>2015-05-21 19:32:02 -0700
commit5db217305f37a79eeccd70f000088a06ec82fcec (patch)
treebe53dcf0c0b47ef9178ab8a6fa5c1946ee84a28f /src/google/protobuf/repeated_field.h
parent56095026ccc2f755a6fdb296e30c3ddec8f556a2 (diff)
down-integrate internal changes
Diffstat (limited to 'src/google/protobuf/repeated_field.h')
-rw-r--r--src/google/protobuf/repeated_field.h60
1 files changed, 28 insertions, 32 deletions
diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h
index 7bfdc40a..5a2fb409 100644
--- a/src/google/protobuf/repeated_field.h
+++ b/src/google/protobuf/repeated_field.h
@@ -576,26 +576,21 @@ class GenericTypeHandler {
}
};
-// Macros for specializing GenericTypeHandler for base proto types, these are
-// are defined here, to allow inlining them at their callsites.
-#define DEFINE_SPECIALIZATIONS_FOR_BASE_PROTO_TYPES(Inline, TypeName) \
- template<> \
- Inline TypeName* GenericTypeHandler<TypeName>::NewFromPrototype( \
- const TypeName* prototype, google::protobuf::Arena* arena) { \
- return prototype->New(arena); \
- } \
- template<> \
- Inline google::protobuf::Arena* GenericTypeHandler<TypeName>::GetArena( \
- TypeName* value) { \
- return value->GetArena(); \
- } \
- template<> \
- Inline void* GenericTypeHandler<TypeName>::GetMaybeArenaPointer( \
- TypeName* value) { \
- return value->GetMaybeArenaPointer(); \
- }
-#define DEFINE_SPECIALIZATIONS_FOR_BASE_PROTO_TYPES_NOINLINE(TypeName) \
- DEFINE_SPECIALIZATIONS_FOR_BASE_PROTO_TYPES(, TypeName)
+template<>
+inline MessageLite* GenericTypeHandler<MessageLite>::NewFromPrototype(
+ const MessageLite* prototype, google::protobuf::Arena* arena) {
+ return prototype->New(arena);
+}
+template<>
+inline google::protobuf::Arena* GenericTypeHandler<MessageLite>::GetArena(
+ MessageLite* value) {
+ return value->GetArena();
+}
+template<>
+inline void* GenericTypeHandler<MessageLite>::GetMaybeArenaPointer(
+ MessageLite* value) {
+ return value->GetMaybeArenaPointer();
+}
// Implements GenericTypeHandler specialization required by RepeatedPtrFields
// to work with MessageLite type.
@@ -605,8 +600,6 @@ inline void GenericTypeHandler<MessageLite>::Merge(
to->CheckTypeAndMergeFrom(from);
}
-DEFINE_SPECIALIZATIONS_FOR_BASE_PROTO_TYPES(inline, MessageLite);
-
// Declarations of the specialization as we cannot define them here, as the
// header that defines ProtocolMessage depends on types defined in this header.
#define DECLARE_SPECIALIZATIONS_FOR_BASE_PROTO_TYPES(TypeName) \
@@ -1235,6 +1228,7 @@ void RepeatedField<Element>::Reserve(int new_size) {
kRepHeaderSize + sizeof(Element)*new_size));
}
rep_->arena = arena;
+ int old_total_size = total_size_;
total_size_ = new_size;
// Invoke placement-new on newly allocated elements. We shouldn't have to do
// this, since Element is supposed to be POD, but a previous version of this
@@ -1253,15 +1247,17 @@ void RepeatedField<Element>::Reserve(int new_size) {
if (current_size_ > 0) {
MoveArray(rep_->elements, old_rep->elements, current_size_);
}
- // Likewise, we need to invoke destructors on the old array. If Element has no
- // destructor, this loop will disappear.
- e = &old_rep->elements[0];
- limit = &old_rep->elements[current_size_];
- for (; e < limit; e++) {
- e->Element::~Element();
- }
- if (arena == NULL) {
- delete[] reinterpret_cast<char*>(old_rep);
+ if (old_rep) {
+ // Likewise, we need to invoke destructors on the old array. If Element has
+ // no destructor, this loop will disappear.
+ e = &old_rep->elements[0];
+ limit = &old_rep->elements[old_total_size];
+ for (; e < limit; e++) {
+ e->Element::~Element();
+ }
+ if (arena == NULL) {
+ delete[] reinterpret_cast<char*>(old_rep);
+ }
}
}
@@ -1418,7 +1414,7 @@ void RepeatedPtrFieldBase::Clear() {
const int n = current_size_;
GOOGLE_DCHECK_GE(n, 0);
if (n > 0) {
- void* const* elements = raw_data();
+ void* const* elements = rep_->elements;
int i = 0;
do {
TypeHandler::Clear(cast<TypeHandler>(elements[i++]));