diff --git a/roofit/roofitcore/inc/RooAbsCollection.h b/roofit/roofitcore/inc/RooAbsCollection.h index 055600ff04bbc..2020ff09dda43 100644 --- a/roofit/roofitcore/inc/RooAbsCollection.h +++ b/roofit/roofitcore/inc/RooAbsCollection.h @@ -356,7 +356,7 @@ class RooAbsCollection : public TObject, public RooPrintable { TString _name; // Our name. Bool_t _allRRV ; // All contents are RRV - void safeDeleteList() ; + void deleteList() ; // Support for snapshot method Bool_t addServerClonesToList(const RooAbsArg& var) ; diff --git a/roofit/roofitcore/src/RooAbsCollection.cxx b/roofit/roofitcore/src/RooAbsCollection.cxx index 9d44a89477a7a..f3eeb0f34d4e8 100644 --- a/roofit/roofitcore/src/RooAbsCollection.cxx +++ b/roofit/roofitcore/src/RooAbsCollection.cxx @@ -198,52 +198,21 @@ RooAbsCollection::~RooAbsCollection() { // Delete all variables in our list if we own them if(_ownCont){ - safeDeleteList() ; + deleteList() ; } } //////////////////////////////////////////////////////////////////////////////// -/// Examine client server dependencies in list and -/// delete contents in safe order: any client -/// is deleted before a server is deleted +/// Delete contents of the list. +/// The RooAbsArg destructor ensures clients and servers can be deleted in any +/// order. +/// Also cleans the hash-map for fast lookups if present. -void RooAbsCollection::safeDeleteList() +void RooAbsCollection::deleteList() { _hashAssistedFind = nullptr; - // Handle trivial case here - if (_list.size() > 1) { - std::vector tmp; - tmp.reserve(_list.size()); - do { - tmp.clear(); - for (auto arg : _list) { - // Check if arg depends on remainder of list - if (!arg->dependsOn(*this, arg)) tmp.push_back(arg); - } - - // sort and uniquify, in case some elements occur more than once - std::sort(tmp.begin(), tmp.end()); - - tmp.erase(std::unique(tmp.begin(), tmp.end()), tmp.end()); - // okay, can remove and delete what's in tmp - auto newEnd = _list.end(); - for (auto item : tmp) { - newEnd = std::remove(_list.begin(), newEnd, item); - delete item; - } - _list.erase(newEnd, _list.end()); - } while (!tmp.empty() && _list.size() > 1); - - // Check if there are any remaining elements - if (_list.size() > 1) { - coutW(ObjectHandling) << "RooAbsCollection::safeDeleteList(" << GetName() - << ") WARNING: unable to delete following elements in client-server order " ; - Print("1") ; - } - } - // Built-in delete remaining elements for (auto item : _list) { delete item; @@ -757,7 +726,7 @@ void RooAbsCollection::removeAll() _hashAssistedFind = nullptr; if(_ownCont) { - safeDeleteList() ; + deleteList() ; _ownCont= kFALSE; } else {