From: Jesse F. Williamson Date: Mon, 10 Feb 2025 17:20:38 +0000 (-0800) Subject: Try out boost::container::flat_map<>. X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2df252ea3c6faa705cb6f67ece387ad2c644167b;p=ceph.git Try out boost::container::flat_map<>. We don't have C++23 available yet. Signed-off-by: Jesse F. Williamson --- diff --git a/src/common/ceph_json.cc b/src/common/ceph_json.cc index af29226a87a..5856b8635ff 100644 --- a/src/common/ceph_json.cc +++ b/src/common/ceph_json.cc @@ -1,10 +1,11 @@ #include "common/ceph_json.h" #include "include/utime.h" -#include +#include #include #include -#include +#include +#include /* Enable boost.json's header-only mode: (see: "https://github.com/boostorg/json?tab=readme-ov-file#header-only"): */ @@ -44,7 +45,7 @@ void JSONObj::handle_value(boost::json::value v) if (auto op = v.if_object()) { for (const auto& kvp : *op) { auto child = std::make_unique(this, kvp.key(), kvp.value()); - children.insert(std::pair { kvp.key(), std::move(child) }); + children.emplace(std::pair { kvp.key(), std::move(child) }); } return; @@ -53,7 +54,7 @@ void JSONObj::handle_value(boost::json::value v) if (auto ap = v.if_array()) { for (const auto& kvp : *ap) { auto child = std::make_unique(this, "", kvp); - children.insert(std::pair { child->get_name(), std::move(child) }); + children.emplace(std::pair { child->get_name(), std::move(child) }); } } diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h index a52a602e036..643ab7d34cd 100644 --- a/src/common/ceph_json.h +++ b/src/common/ceph_json.h @@ -111,7 +111,7 @@ concept json_val_seq = requires class JSONObjIter final { - using map_iter_t = std::map, std::less<>>::iterator; + using map_iter_t = boost::container::flat_map, std::less<>>::iterator; map_iter_t cur; map_iter_t last; @@ -147,10 +147,6 @@ class JSONObj { JSONObj *parent = nullptr; -protected: - using children_multimap_t = std::multimap, std::less<>>; - using children_multimap_value_type = typename children_multimap_t::value_type; - public: struct data_val { std::string str; @@ -171,8 +167,8 @@ protected: bool data_quoted{false}; - children_multimap_t children; - std::map> attr_map; + boost::container::flat_multimap, std::less<>> children; + boost::container::flat_map> attr_map; void handle_value(boost::json::value v); @@ -640,7 +636,7 @@ public: }; private: - std::map handlers; + boost::container::flat_map handlers; public: void register_type(HandlerBase *h) {