From d64a2d9941c36a7bc2a7959ea10ab8363192ac14 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 29 Jun 2016 15:23:27 -0700 Subject: Integrated internal changes from Google This includes all internal changes from around May 20 to now. --- src/google/protobuf/map.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/google/protobuf/map.h') 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 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 { -- cgit v1.2.3