]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Try out boost::container::flat_map<>.
authorJesse F. Williamson <jfw@ibm.com>
Mon, 10 Feb 2025 17:20:38 +0000 (09:20 -0800)
committerJesse F. Williamson <jfw@ibm.com>
Mon, 17 Mar 2025 17:41:27 +0000 (10:41 -0700)
We don't have C++23 available yet.

Signed-off-by: Jesse F. Williamson <jfw@ibm.com>
src/common/ceph_json.cc
src/common/ceph_json.h

index af29226a87a191fb42c4f6856d7e86100ec0c51d..5856b8635ff0914fffa05ad7081dbe2103125d77 100644 (file)
@@ -1,10 +1,11 @@
 #include "common/ceph_json.h"
 #include "include/utime.h"
 
-#include <boost/algorithm/string.hpp>
+#include <include/types.h>
 #include <boost/tokenizer.hpp>
 #include <boost/lexical_cast.hpp>
-#include <include/types.h>
+#include <boost/algorithm/string.hpp>
+#include <boost/container/flat_map.hpp>
 
 /* 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<JSONObj>(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<JSONObj>(this, "", kvp);
-               children.insert(std::pair { child->get_name(), std::move(child) });
+               children.emplace(std::pair { child->get_name(), std::move(child) });
         }
  }
 
index a52a602e036dd284b6c60f452a0392944cbed547..643ab7d34cd4689d391403234523764191d5ae0a 100644 (file)
@@ -111,7 +111,7 @@ concept json_val_seq = requires
 
 class JSONObjIter final {
 
-  using map_iter_t = std::map<std::string, std::unique_ptr<JSONObj>, std::less<>>::iterator;
+  using map_iter_t = boost::container::flat_map<std::string, std::unique_ptr<JSONObj>, 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::string, std::unique_ptr<JSONObj>, 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<std::string, data_val, std::less<>> attr_map;
+  boost::container::flat_multimap<std::string, std::unique_ptr<JSONObj>, std::less<>> children;
+  boost::container::flat_map<std::string, data_val, std::less<>> attr_map;
 
   void handle_value(boost::json::value v);
 
@@ -640,7 +636,7 @@ public:
   };
 
 private:
-  std::map<std::type_index, HandlerBase *> handlers;
+  boost::container::flat_map<std::type_index, HandlerBase *> handlers;
 
 public:
   void register_type(HandlerBase *h) {