aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/unknown_field_set.h
diff options
context:
space:
mode:
authorGravatar Feng Xiao <xfxyjwf@gmail.com>2014-11-10 17:34:54 -0800
committerGravatar Feng Xiao <xfxyjwf@gmail.com>2014-11-10 17:34:54 -0800
commit6ef984af4b0c63c1c33127a12dcfc8e6359f0c9e (patch)
treed17c61ff9f3ae28224fbddac6d26bfc59e2cf755 /src/google/protobuf/unknown_field_set.h
parentbaca1a8a1aa180c42de6278d3b8286c4496c6a10 (diff)
Down-integrate from internal code base.
Diffstat (limited to 'src/google/protobuf/unknown_field_set.h')
-rw-r--r--src/google/protobuf/unknown_field_set.h29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/google/protobuf/unknown_field_set.h b/src/google/protobuf/unknown_field_set.h
index 31f17e2a..6f7a9fdb 100644
--- a/src/google/protobuf/unknown_field_set.h
+++ b/src/google/protobuf/unknown_field_set.h
@@ -88,6 +88,9 @@ class LIBPROTOBUF_EXPORT UnknownFieldSet {
// Merge the contents of some other UnknownFieldSet with this one.
void MergeFrom(const UnknownFieldSet& other);
+ // Similar to above, but this function will destroy the contents of other.
+ void MergeFromAndDestroy(UnknownFieldSet* other);
+
// Swaps the contents of some other UnknownFieldSet with this one.
inline void Swap(UnknownFieldSet* x);
@@ -141,12 +144,22 @@ class LIBPROTOBUF_EXPORT UnknownFieldSet {
return ParseFromArray(data.data(), static_cast<int>(data.size()));
}
+ static const UnknownFieldSet* default_instance();
private:
-
+ // For InternalMergeFrom
+ friend class UnknownField;
+ // Merges from other UnknownFieldSet. This method assumes, that this object
+ // is newly created and has fields_ == NULL;
+ void InternalMergeFrom(const UnknownFieldSet& other);
void ClearFallback();
+ // fields_ is either NULL, or a pointer to a vector that is *non-empty*. We
+ // never hold the empty vector because we want the 'do we have any unknown
+ // fields' check to be fast, and avoid a cache miss: the UFS instance gets
+ // embedded in the message object, so 'fields_ != NULL' tests a member
+ // variable hot in the cache, without the need to go touch a vector somewhere
+ // else in memory.
std::vector<UnknownField>* fields_;
-
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UnknownFieldSet);
};
@@ -198,6 +211,10 @@ class LIBPROTOBUF_EXPORT UnknownField {
// If this UnknownField contains a pointer, delete it.
void Delete();
+ // Reset all the underlying pointers to NULL. A special function to be only
+ // used while merging from a temporary UFS.
+ void Reset();
+
// Make a deep copy of any pointers in this UnknownField.
void DeepCopy();
@@ -222,13 +239,14 @@ class LIBPROTOBUF_EXPORT UnknownField {
// inline implementations
inline void UnknownFieldSet::Clear() {
- if (fields_ != NULL) {
+ if (fields_) {
ClearFallback();
}
}
inline bool UnknownFieldSet::empty() const {
- return fields_ == NULL || fields_->empty();
+ // Invariant: fields_ is never empty if present.
+ return !fields_;
}
inline void UnknownFieldSet::Swap(UnknownFieldSet* x) {
@@ -236,9 +254,10 @@ inline void UnknownFieldSet::Swap(UnknownFieldSet* x) {
}
inline int UnknownFieldSet::field_count() const {
- return (fields_ == NULL) ? 0 : static_cast<int>(fields_->size());
+ return fields_ ? static_cast<int>(fields_->size()) : 0;
}
inline const UnknownField& UnknownFieldSet::field(int index) const {
+ GOOGLE_DCHECK(fields_ != NULL);
return (*fields_)[index];
}
inline UnknownField* UnknownFieldSet::mutable_field(int index) {