Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osd/OSD.h: change iterator to const_iterator #9387

Merged
merged 1 commit into from
Jun 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/osd/OSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ class OSDService {
Mutex::Locker l(pre_publish_lock);
assert(next_osdmap);
while (true) {
map<epoch_t, unsigned>::iterator i = map_reservations.begin();
if (i == map_reservations.end() || i->first >= next_osdmap->get_epoch()) {
map<epoch_t, unsigned>::const_iterator i = map_reservations.cbegin();
if (i == map_reservations.cend() || i->first >= next_osdmap->get_epoch()) {
break;
} else {
pre_publish_cond.Wait(pre_publish_lock);
Expand Down Expand Up @@ -669,11 +669,11 @@ class OSDService {
Mutex::Locker l(sched_scrub_lock);
if (sched_scrub_pg.empty())
return false;
set<ScrubJob>::iterator iter = sched_scrub_pg.lower_bound(next);
if (iter == sched_scrub_pg.end())
set<ScrubJob>::const_iterator iter = sched_scrub_pg.lower_bound(next);
if (iter == sched_scrub_pg.cend())
return false;
++iter;
if (iter == sched_scrub_pg.end())
if (iter == sched_scrub_pg.cend())
return false;
*out = *iter;
return true;
Expand Down Expand Up @@ -1166,8 +1166,8 @@ class OSDService {
void dump_live_pgids() {
Mutex::Locker l(pgid_lock);
derr << "live pgids:" << dendl;
for (map<spg_t, int>::iterator i = pgid_tracker.begin();
i != pgid_tracker.end();
for (map<spg_t, int>::const_iterator i = pgid_tracker.cbegin();
i != pgid_tracker.cend();
++i) {
derr << "\t" << *i << dendl;
live_pgs[i->first]->dump_live_ids();
Expand Down Expand Up @@ -1453,9 +1453,9 @@ class OSD : public Dispatcher,

void clear_waiting_sessions() {
Mutex::Locker l(session_waiting_lock);
for (map<spg_t, set<Session*> >::iterator i =
session_waiting_for_pg.begin();
i != session_waiting_for_pg.end();
for (map<spg_t, set<Session*> >::const_iterator i =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this creates a const_iterator from an iterator. which incurs the cost of calling a copy ctor. if you want to make sure that we are using the const_iterator for reading containers. maybe you could use auto, session_waiting_for_pg.cbegin(), session_waiting_for_pg.cend() instead?

session_waiting_for_pg.cbegin();
i != session_waiting_for_pg.cend();
++i) {
for (set<Session*>::iterator j = i->second.begin();
j != i->second.end();
Expand Down Expand Up @@ -1525,9 +1525,9 @@ class OSD : public Dispatcher,
Mutex::Locker l(session->session_dispatch_lock);
clear_session_waiting_on_map(session);

for (map<spg_t, list<OpRequestRef> >::iterator i =
session->waiting_for_pg.begin();
i != session->waiting_for_pg.end();
for (map<spg_t, list<OpRequestRef> >::const_iterator i =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

session->waiting_for_pg.cbegin();
i != session->waiting_for_pg.cend();
++i) {
clear_session_waiting_on_pg(session, i->first);
}
Expand All @@ -1544,8 +1544,8 @@ class OSD : public Dispatcher,
void register_session_waiting_on_pg(Session *session, spg_t pgid) {
Mutex::Locker l(session_waiting_lock);
set<Session*> &s = session_waiting_for_pg[pgid];
set<Session*>::iterator i = s.find(session);
if (i == s.end()) {
set<Session*>::const_iterator i = s.find(session);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd not suggest use set<Session*>::const_iterator here, unless we have a simple way to avoid the unnecessary copy ctor.

if (i == s.cend()) {
session->get();
s.insert(session);
}
Expand Down Expand Up @@ -1883,11 +1883,11 @@ class OSD : public Dispatcher,
// items in pqueue are behind items in pg_for_processing
sdata->pqueue->remove_by_filter(f);

map<PG *, list<PGQueueable> >::iterator iter =
map<PG *, list<PGQueueable> >::const_iterator iter =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

sdata->pg_for_processing.find(pg);
if (iter != sdata->pg_for_processing.end()) {
for (auto i = iter->second.rbegin();
i != iter->second.rend();
if (iter != sdata->pg_for_processing.cend()) {
for (auto i = iter->second.crbegin();
i != iter->second.crend();
++i) {
f.accumulate(*i);
}
Expand Down