aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/map.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/map.h')
-rw-r--r--src/google/protobuf/map.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h
index 31593c1a..42bcfd94 100644
--- a/src/google/protobuf/map.h
+++ b/src/google/protobuf/map.h
@@ -520,7 +520,7 @@ class Map {
typedef size_t size_type;
typedef hash<Key> hasher;
- Map(bool old_style = true)
+ explicit Map(bool old_style = true)
: arena_(NULL),
default_enum_value_(0),
old_style_(old_style) {
@@ -1621,6 +1621,24 @@ class Map {
return *this;
}
+ void swap(Map& other) {
+ if (arena_ == other.arena_ && old_style_ == other.old_style_) {
+ std::swap(default_enum_value_, other.default_enum_value_);
+ if (old_style_) {
+ std::swap(deprecated_elements_, other.deprecated_elements_);
+ } else {
+ std::swap(elements_, other.elements_);
+ }
+ } else {
+ // TODO(zuguang): optimize this. The temporary copy can be allocated
+ // in the same arena as the other message, and the "other = copy" can
+ // be replaced with the fast-path swap above.
+ Map copy = *this;
+ *this = other;
+ other = copy;
+ }
+ }
+
// Access to hasher. Currently this returns a copy, but it may
// be modified to return a const reference in the future.
hasher hash_function() const {