@@ -437,21 +437,23 @@ SetPerimeter UnorderedSet::perimeter() const
437437
438438void UnorderedSet::compact ()
439439{
440+ using MDISet = std::set<MultiDimInter>;
441+
440442 MDIUnordCollection result;
441443
442444 if (!isEmpty ()) {
443- std::set<MultiDimInter> prev{_pieces.begin (), _pieces.end ()};
444- std::set<MultiDimInter> actual = prev;
445+ MDISet set_result{std::make_move_iterator (_pieces.begin ())
446+ , std::make_move_iterator (_pieces.end ())};
447+ MDISet to_erase;
445448 do {
446- prev = actual ;
447- actual = std::set<MultiDimInter>{} ;
449+ MDISet new_set_result ;
450+ to_erase. clear () ;
448451
449- std::set<MultiDimInter>::iterator ith = prev.begin ();
450- std::set<MultiDimInter>::iterator last = prev.end ();
451- std::set<MultiDimInter> to_erase;
452+ MDISet::iterator ith = set_result.begin ();
453+ MDISet::iterator last = set_result.end ();
452454 for (; ith != last; ++ith) {
453455 MultiDimInter ith_compact = *ith;
454- std::set<MultiDimInter> ::iterator next = ith;
456+ MDISet ::iterator next = ith;
455457 ++next;
456458 for (; next != last; ++next) {
457459 MaybeMDI new_compact = ith_compact.compact (*next);
@@ -462,13 +464,15 @@ void UnorderedSet::compact()
462464 }
463465
464466 if (to_erase.find (ith_compact) == to_erase.end ()) {
465- actual .insert (ith_compact);
467+ new_set_result .insert (ith_compact);
466468 }
467- }
468- } while (actual != prev);
469+ }
470+
471+ std::swap (set_result, new_set_result);
472+ } while (!to_erase.empty ());
469473
470- for (const MultiDimInter& mdi : actual ) {
471- result.push_back (mdi );
474+ for (const MultiDimInter& m : set_result ) {
475+ result.push_back (m );
472476 }
473477 }
474478
0 commit comments