]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: get largest bucket id faster
authorKefu Chai <kchai@redhat.com>
Wed, 30 Aug 2017 07:30:58 +0000 (15:30 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 30 Aug 2017 07:31:56 +0000 (15:31 +0800)
std::map<> is sorted, so we can always get the largest key by reading
it's last element.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crush/CrushWrapper.cc

index bf6f3cf5ab8d69aa7bea8ad4562d0a1093102b9b..4a73b6feba24228afbfc648175658f7605075df2 100644 (file)
@@ -765,10 +765,8 @@ map<int, string> CrushWrapper::get_parent_hierarchy(int id)
 
   // read the type map and get the name of the type with the largest ID
   int high_type = 0;
-  for (map<int, string>::iterator it = type_map.begin(); it != type_map.end(); ++it){
-    if ( (*it).first > high_type )
-      high_type = (*it).first;
-  }
+  if (!type_map.empty())
+    high_type = type_map.rbegin()->first;
 
   parent_id = get_item_id(parent_coord.second);