]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw_tag: move from std::map -> boost::flat_map
authorAbhishek Lekshmanan <abhishek@suse.com>
Tue, 13 Jun 2017 18:12:38 +0000 (20:12 +0200)
committerAbhishek Lekshmanan <abhishek@suse.com>
Wed, 21 Jun 2017 12:10:45 +0000 (14:10 +0200)
well since flat_map is a vector under the hood it should be faster for
such small sizes, also renaming tags to a more understandable tag_map.

Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
src/rgw/rgw_tag.cc
src/rgw/rgw_tag.h
src/rgw/rgw_tag_s3.cc

index 682088e569d8fc910835335ca67cec0dcf7a425b..76b361f4deadee19b602176845d871d7b561bd34 100644 (file)
@@ -12,11 +12,11 @@ static constexpr uint32_t MAX_TAG_KEY_SIZE=128;
 static constexpr uint32_t MAX_TAG_VAL_SIZE=256;
 
 bool RGWObjTags::add_tag(const string&key, const string& val){
-  return tags.emplace(std::make_pair(key,val)).second;
+  return tag_map.emplace(std::make_pair(key,val)).second;
 }
 
 int RGWObjTags::check_and_add_tag(const string&key, const string& val){
-  if (tags.size() == MAX_OBJ_TAGS ||
+  if (tag_map.size() == MAX_OBJ_TAGS ||
       key.size() > MAX_TAG_KEY_SIZE ||
       val.size() > MAX_TAG_VAL_SIZE ||
       key.size() == 0){
index 93b5d9a292177efc8f004a695c5ba5e48d099773..f5d787ae9b2546a3d92a36ab07750a000bb81977 100644 (file)
@@ -1,38 +1,39 @@
 #ifndef RGW_TAG_H
 #define RGW_TAG_H
 
-#include <map>
 #include <string>
 #include <include/types.h>
+#include <boost/container/flat_map.hpp>
 
 #include "rgw_common.h"
 
 class RGWObjTags
 {
  protected:
-  std::map <std::string, std::string> tags;
+  using tag_map_t = boost::container::flat_map <std::string, std::string>;
+  tag_map_t tag_map;
  public:
   RGWObjTags() {}
   ~RGWObjTags() {}
 
   void encode(bufferlist& bl) const {
     ENCODE_START(1,1,bl);
-    ::encode(tags, bl);
+    ::encode(tag_map, bl);
     ENCODE_FINISH(bl);
   }
 
   void decode(bufferlist::iterator &bl) {
     DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl);
-    ::decode(tags,bl);
+    ::decode(tag_map,bl);
     DECODE_FINISH(bl);
   }
 
   void dump(Formatter *f) const;
   bool add_tag(const std::string& key, const std::string& val="");
   int check_and_add_tag(const std::string& key, const std::string& val="");
-  size_t count() const {return tags.size();}
+  size_t count() const {return tag_map.size();}
   int set_from_string(const std::string& input);
-  const map <std::string,std::string>& get_tags() const {return tags;}
+  const tag_map_t& get_tags() const {return tag_map;}
 };
 WRITE_CLASS_ENCODER(RGWObjTags)
 
index b29aed5109916c4727fbf722c1765b867522bd8d..1b7f717c96b98d52d27971c18a52db4d04df9106 100644 (file)
@@ -42,7 +42,7 @@ bool RGWObjTagSet_S3::xml_end(const char*){
 
 int RGWObjTagSet_S3::rebuild(RGWObjTags& dest){
   int ret;
-  for (const auto &it: tags){
+  for (const auto &it: tag_map){
     ret = dest.check_and_add_tag(it.first, it.second);
     if (ret < 0)
       return ret;
@@ -57,7 +57,7 @@ bool RGWObjTagging_S3::xml_end(const char*){
 }
 
 void RGWObjTagSet_S3::dump_xml(Formatter *f){
-  for (const auto& tag: tags){
+  for (const auto& tag: tag_map){
     f->open_object_section("Tag");
     f->dump_string("Key", tag.first);
     f->dump_string("Value", tag.second);