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: Making use of find to reduce computational complexity #19732

Merged
merged 1 commit into from Jan 8, 2018

Conversation

shinobu-x
Copy link
Contributor

Signed-off-by: Shinobu Kinjo shinobu@redhat.com

Copy link
Contributor

@tchaikov tchaikov left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@liewegas liewegas left a comment

Choose a reason for hiding this comment

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

I skimmed quickly but only that one case looked like it would benefit from a change.

@@ -424,7 +424,7 @@ void PrimaryLogPG::on_local_recover(
bool got = obc->get_recovery_read();
assert(got);

assert(recovering.count(obc->obs.oi.soid));
assert(recovering.find(obc->obs.oi.soid) != recovering.end());
Copy link
Member

Choose a reason for hiding this comment

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

This changes aren't helpful/useful.. the complexity is the same and they are more verbose.

The point is get rid of patterns like:

if (foo.count(bar) && foo[bar] == baz) {

where a count() precedes an operator[] call. That is two lookups but can be reduced to 1 by using an iterator and comparing to end().

@@ -755,7 +761,7 @@ void PrimaryLogPG::maybe_force_recovery()
++it) {
if (*it == get_primary()) continue;
pg_shard_t peer = *it;
if (peer_missing.count(peer) &&
if (peer_missing.find(peer) != peer_missing.end() &&
Copy link
Member

Choose a reason for hiding this comment

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

Like here:

auto it = peer_missing.find(peer);
if (it != peer_missing.end() &&
   !it->second.get_rmissing.empty()) {
...

Signed-off-by: Shinobu Kinjo <shinobu@redhat.com>
@shinobu-x shinobu-x changed the title osd: Using find, count instead osd: Making use of find to reduce computational complexity Jan 2, 2018
@shinobu-x
Copy link
Contributor Author

@liewegas Please check when you get a chance.

Copy link
Member

@liewegas liewegas left a comment

Choose a reason for hiding this comment

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

great!

@yuriw
Copy link
Contributor

yuriw commented Jan 5, 2018

@yuriw yuriw merged commit b63708c into ceph:master Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants