From dcd1687562c08a4babb4e145f605492da31ab7f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Piotr=20Da=C5=82ek?= Date: Tue, 18 Apr 2017 13:46:11 +0200 Subject: [PATCH] common/interval_set.h: add move_into() and new ctor MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit move_into() will be used to move data from internal (private) std::map into other, external std::map, without exposing internal one to public. New ctor improves moving data from external map to internal one. Signed-off-by: Piotr Dałek --- src/include/interval_set.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/include/interval_set.h b/src/include/interval_set.h index 9fa2d4a8bec..52c3f57ac4f 100644 --- a/src/include/interval_set.h +++ b/src/include/interval_set.h @@ -153,6 +153,13 @@ class interval_set { }; interval_set() : _size(0) {} + interval_set(std::map& other) { + m.swap(other); + _size = 0; + for (auto& i : m) { + _size += i.second; + } + } int num_intervals() const { @@ -548,6 +555,14 @@ class interval_set { } } + /* + * Move contents of m into another std::map. Use that instead of + * encoding interval_set into bufferlist then decoding it back into std::map. + */ + void move_into(std::map& other) { + other = std::move(m); + } + private: // data int64_t _size; -- 2.47.3