From: Kefu Chai Date: Wed, 30 Aug 2017 07:30:58 +0000 (+0800) Subject: crush: get largest bucket id faster X-Git-Tag: v13.0.1~1095^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9ec4e216cbf4bf065bd1da77ec6fbc5c96760f2d;p=ceph-ci.git crush: get largest bucket id faster std::map<> is sorted, so we can always get the largest key by reading it's last element. Signed-off-by: Kefu Chai --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index bf6f3cf5ab8..4a73b6feba2 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -765,10 +765,8 @@ map 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::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);