From: Danny Al-Gaaf Date: Wed, 13 Feb 2013 14:18:55 +0000 (+0100) Subject: PG.cc: use empty() instead of size() to check for emptiness X-Git-Tag: v0.58~66^2~45 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d9a063828b7fb9732a5b158e424ec6c6368ff8ee;p=ceph.git PG.cc: use empty() instead of size() to check for emptiness Use empty() since it should be prefered as it has, following the standard, a constant time complexity regardless of the containter type. The same is not guaranteed for size(). This replaces also some size() >=/== checks. Signed-off-by: Danny Al-Gaaf --- diff --git a/src/osd/PG.cc b/src/osd/PG.cc index 7fd4144983dd..b66d9924bca7 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -2816,7 +2816,7 @@ void PG::update_snap_collections(vector &log_entries, } catch (...) { snaps.clear(); } - if (snaps.size()) { + if (!snaps.empty()) { make_snap_collection(t, snaps[0]); if (snaps.size() > 1) make_snap_collection(t, *(snaps.rbegin())); @@ -3803,7 +3803,7 @@ void PG::chunky_scrub() { start = scrubber.end; // special case: reached end of file store, implicitly a boundary - if (objects.size() == 0) { + if (objects.empty()) { break; } @@ -4121,13 +4121,13 @@ void PG::_compare_scrubmaps(const map &maps, } } assert(auth != maps.end()); - if (cur_missing.size()) { + if (!cur_missing.empty()) { missing[*k] = cur_missing; } - if (cur_inconsistent.size()) { + if (!cur_inconsistent.empty()) { inconsistent[*k] = cur_inconsistent; } - if (cur_inconsistent.size() || cur_missing.size()) { + if (!cur_inconsistent.empty() || !cur_missing.empty()) { authoritative[*k] = auth->first; } } @@ -4162,7 +4162,7 @@ void PG::scrub_compare_maps() { ss); dout(2) << ss.str() << dendl; - if (authoritative.size() || scrubber.inconsistent_snapcolls.size()) { + if (!authoritative.empty() || !scrubber.inconsistent_snapcolls.empty()) { osd->clog.error(ss); } @@ -4186,7 +4186,7 @@ void PG::scrub_process_inconsistent() { bool deep_scrub = state_test(PG_STATE_DEEP_SCRUB); const char *mode = (repair ? "repair": (deep_scrub ? "deep-scrub" : "scrub")); - if (scrubber.authoritative.size() || scrubber.inconsistent.size()) { + if (!scrubber.authoritative.empty() || !scrubber.inconsistent.empty()) { stringstream ss; for (map >::iterator obj = scrubber.inconsistent_snapcolls.begin(); @@ -4735,7 +4735,7 @@ void PG::start_peering_interval(const OSDMapRef lastmap, osd->remove_want_pg_temp(info.pgid); cancel_recovery(); - if (acting.empty() && up.size() && up[0] == osd->whoami) { + if (acting.empty() && !up.empty() && up[0] == osd->whoami) { dout(10) << " acting empty, but i am up[0], clearing pg_temp" << dendl; osd->queue_want_pg_temp(info.pgid, acting); } @@ -4776,7 +4776,7 @@ ostream& operator<<(ostream& out, const PG& pg) out << " r=" << pg.get_role(); out << " lpr=" << pg.get_last_peering_reset(); - if (pg.past_intervals.size()) { + if (!pg.past_intervals.empty()) { out << " pi=" << pg.past_intervals.begin()->first << "-" << pg.past_intervals.rbegin()->second.last << "/" << pg.past_intervals.size(); } @@ -6701,7 +6701,7 @@ PG::RecoveryState::GetLog::GetLog(my_context ctx) : // adjust acting? if (!pg->choose_acting(newest_update_osd)) { - if (pg->want_acting.size()) { + if (!pg->want_acting.empty()) { post_event(NeedActingChange()); } else { post_event(IsIncomplete());