From: Piotr Dałek Date: Tue, 18 Apr 2017 11:46:11 +0000 (+0200) Subject: common/interval_set.h: add move_into() and new ctor X-Git-Tag: v12.0.3~316^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dcd1687562c08a4babb4e145f605492da31ab7f6;p=ceph.git common/interval_set.h: add move_into() and new ctor 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 --- diff --git a/src/include/interval_set.h b/src/include/interval_set.h index 9fa2d4a8bec8..52c3f57ac4f1 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;