From e39f601295b158c184c8169325cf9624f8e88f7c Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 18 Sep 2024 12:31:09 -0400 Subject: [PATCH] cls/rgw: cls_rgw_obj_chain uses vector instead of list Signed-off-by: Casey Bodley --- src/cls/rgw/cls_rgw_types.h | 11 +++++------ src/rgw/driver/rados/rgw_gc.cc | 5 +---- src/rgw/rgw_admin.cc | 5 +---- src/test/cls_rgw/test_cls_rgw.cc | 4 ++-- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/cls/rgw/cls_rgw_types.h b/src/cls/rgw/cls_rgw_types.h index e6afe47ffc7d1..1bfcbcc97b89e 100644 --- a/src/cls/rgw/cls_rgw_types.h +++ b/src/cls/rgw/cls_rgw_types.h @@ -5,6 +5,7 @@ #include #include +#include #include #include "common/ceph_time.h" #include "common/Formatter.h" @@ -1197,16 +1198,14 @@ struct cls_rgw_obj { WRITE_CLASS_ENCODER(cls_rgw_obj) struct cls_rgw_obj_chain { - std::list objs; - - cls_rgw_obj_chain() {} + std::vector objs; void push_obj(const std::string& pool, const cls_rgw_obj_key& key, const std::string& loc) { cls_rgw_obj obj; obj.pool = pool; obj.key = key; obj.loc = loc; - objs.push_back(obj); + objs.push_back(std::move(obj)); } void encode(ceph::buffer::list& bl) const { @@ -1223,9 +1222,9 @@ struct cls_rgw_obj_chain { void dump(ceph::Formatter *f) const { f->open_array_section("objs"); - for (std::list::const_iterator p = objs.begin(); p != objs.end(); ++p) { + for (const auto& o : objs) { f->open_object_section("obj"); - p->dump(f); + o.dump(f); f->close_section(); } f->close_section(); diff --git a/src/rgw/driver/rados/rgw_gc.cc b/src/rgw/driver/rados/rgw_gc.cc index 7a4e22608bdd7..18c8b75ca4d83 100644 --- a/src/rgw/driver/rados/rgw_gc.cc +++ b/src/rgw/driver/rados/rgw_gc.cc @@ -653,7 +653,6 @@ int RGWGC::process(int index, int max_secs, bool expired_only, info.tag << "', time=" << info.time << ", chain.objs.size()=" << info.chain.objs.size() << dendl; - std::list::iterator liter; cls_rgw_obj_chain& chain = info.chain; utime_t now = ceph_clock_now(); @@ -668,9 +667,7 @@ int RGWGC::process(int index, int max_secs, bool expired_only, } } if (! chain.objs.empty()) { - for (liter = chain.objs.begin(); liter != chain.objs.end(); ++liter) { - cls_rgw_obj& obj = *liter; - + for (const auto& obj : chain.objs) { if (obj.pool != last_pool) { delete ctx; ctx = new IoCtx; diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index d1b041f2423fe..a8874195217a2 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -8806,10 +8806,7 @@ next: formatter->dump_string("tag", info.tag); formatter->dump_stream("time") << info.time; formatter->open_array_section("objs"); - list::iterator liter; - cls_rgw_obj_chain& chain = info.chain; - for (liter = chain.objs.begin(); liter != chain.objs.end(); ++liter) { - cls_rgw_obj& obj = *liter; + for (const auto& obj : info.chain.objs) { encode_json("obj", obj, formatter.get()); } formatter->close_section(); // objs diff --git a/src/test/cls_rgw/test_cls_rgw.cc b/src/test/cls_rgw/test_cls_rgw.cc index 23c3576429a69..630f6b8ecd6c8 100644 --- a/src/test/cls_rgw/test_cls_rgw.cc +++ b/src/test/cls_rgw/test_cls_rgw.cc @@ -854,7 +854,7 @@ TEST_F(cls_rgw, gc_set) /* verify expected num of objects in chain */ ASSERT_EQ(2, (int)entry.chain.objs.size()); - list::iterator oiter = entry.chain.objs.begin(); + auto oiter = entry.chain.objs.begin(); cls_rgw_obj obj1, obj2; /* create expected objects */ @@ -932,7 +932,7 @@ TEST_F(cls_rgw, gc_list) /* verify expected num of objects in chain */ ASSERT_EQ(2, (int)entry.chain.objs.size()); - list::iterator oiter = entry.chain.objs.begin(); + auto oiter = entry.chain.objs.begin(); cls_rgw_obj obj1, obj2; /* create expected objects */ -- 2.39.5