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

use STL find() and iterators instead of count() #16630

Closed
wants to merge 1 commit into from

Conversation

amitkumar50
Copy link

This PR is 1st part of replacement of if(container.count(foo)) with container.find(foo). Since the .count(foo) code searches for key till end and returns TRUE/FALSE, it's good to quit the search if we find the key at 1st instance.
After this PR gets rolled out, similar PRs would be created for other modules as well.

Resolves: http://tracker.ceph.com/issues/432

Signed-off-by: Amit Kumar amitkuma@redhat.com

@@ -443,7 +443,7 @@ int AdminSocket::register_command(std::string command, std::string cmddesc, Admi
{
int ret;
m_lock.Lock();
if (m_hooks.count(command)) {
if (m_hooks.find(command) != m_hooks.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

quote from bits/stl_map.h

      size_type
      count(const key_type& __x) const
      { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }

Copy link
Author

Choose a reason for hiding this comment

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

   *  This function only makes sense for multimaps; for map the result will
   *  either be 0 (not present) or 1 (present).
   */

@tchaikov tchaikov closed this Jul 27, 2017
This PR is 1st part of replacement of if(container.count(foo)) with container.find(foo). Since the .count(foo) code searches for key till end and returns TRUE/FALSE, it's good to quit the search if we find the key at 1st instance.
After this PR gets rolled out, similar PRs would be created for other modules as well.

Resolves: http://tracker.ceph.com/issues/432

Signed-off-by: Amit Kumar amitkuma@redhat.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants