From: Abhishek Lekshmanan Date: Tue, 13 Jun 2017 18:12:38 +0000 (+0200) Subject: rgw_tag: move from std::map -> boost::flat_map X-Git-Tag: v12.1.2~1^2~48^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fcbac837049a02107d3a46af46b80658528d4b70;p=ceph.git rgw_tag: move from std::map -> boost::flat_map 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 --- diff --git a/src/rgw/rgw_tag.cc b/src/rgw/rgw_tag.cc index 682088e569d8..76b361f4dead 100644 --- a/src/rgw/rgw_tag.cc +++ b/src/rgw/rgw_tag.cc @@ -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){ diff --git a/src/rgw/rgw_tag.h b/src/rgw/rgw_tag.h index 93b5d9a29217..f5d787ae9b25 100644 --- a/src/rgw/rgw_tag.h +++ b/src/rgw/rgw_tag.h @@ -1,38 +1,39 @@ #ifndef RGW_TAG_H #define RGW_TAG_H -#include #include #include +#include #include "rgw_common.h" class RGWObjTags { protected: - std::map tags; + using tag_map_t = boost::container::flat_map ; + 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 & get_tags() const {return tags;} + const tag_map_t& get_tags() const {return tag_map;} }; WRITE_CLASS_ENCODER(RGWObjTags) diff --git a/src/rgw/rgw_tag_s3.cc b/src/rgw/rgw_tag_s3.cc index b29aed510991..1b7f717c96b9 100644 --- a/src/rgw/rgw_tag_s3.cc +++ b/src/rgw/rgw_tag_s3.cc @@ -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);