From: Roland McGrath Date: Tue, 27 Jan 2009 09:47:43 +0000 (-0800) Subject: Coalesce adjacent ranges for comparison. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9d271bfad68bfa02cf7f3f83395417e550c28efd;p=thirdparty%2Felfutils.git Coalesce adjacent ranges for comparison. --- diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index e118f49a5..4eda3bb54 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -1147,7 +1147,7 @@ namespace elfutils public: inline const_iterator (const const_iterator &i) - : _m_base (i._m_base), _m_begin (i._m_begin), _m_end (i._m_begin), + : _m_base (i._m_base), _m_begin (i._m_begin), _m_end (i._m_end), _m_cu (i._m_cu), _m_offset (i._m_offset) {} inline value_type operator* () const @@ -1227,8 +1227,10 @@ namespace elfutils is conceptually equal if all the pairs match, regardless of the order. But the std::equal algorithm will compare corresponding elements in order. So we need an ordered set for comparison. */ - const std::set mine = *this; - const std::set his = other; + std::set mine = *this; + coalesce (mine); + std::set his = other; + coalesce (his); return mine == his; } template @@ -1435,8 +1437,10 @@ namespace elfutils is conceptually equal if all the pairs match, regardless of the order. But the std::equal algorithm will compare corresponding elements in order. So we need an ordered set for comparison. */ - const std::set mine = *this; - const std::set his = other; + std::set mine = *this; + coalesce (mine); + std::set his = other; + coalesce (his); return mine == his; } template @@ -1646,6 +1650,30 @@ namespace elfutils typedef std::map aranges_map; aranges_map aranges () const; + + private: + static bool adjacency (const arange_list::key_type &a, + const arange_list::key_type &b) + { + return a.second == b.first; + } + + // Coalesce adjacent ranges. + static void coalesce (std::set &set) + { + for (std::set::iterator i = set.begin (); + (i = std::adjacent_find (i, set.end (), adjacency)) != set.end (); + ++i) + { + std::set::iterator j = i; + std::set::iterator k = ++j; + while (++k != set.end () && adjacency (*j, *k)) + ++j; + const arange_list::key_type joined ((*i).first, (*j).second); + set.erase (i, k); + i = set.insert (joined).first; + } + } }; inline class dwarf::debug_info_entry::raw_children