From 9ec4e216cbf4bf065bd1da77ec6fbc5c96760f2d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 30 Aug 2017 15:30:58 +0800 Subject: [PATCH] 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 --- src/crush/CrushWrapper.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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); -- 2.39.5