Skip to content

Commit 359e187

Browse files
committed
[core] Make TDirectory::Append tolerant to identical objects.
When calling TDirectory::Append(obj, replace=true), and obj is already in the directory, return without doing anything. If obj has the same name as an existing object, but is physically different, the usual warning is raised. This will enable workflows such as: auto h = new TH1D(...); directory->Append(h, true); After this change, the above lines work both with and without auto registration to gDirectory. This is needed to prepare ROOT for working without auto registration.
1 parent 7a9298c commit 359e187

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

core/base/src/TDirectory.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ void TDirectory::Append(TObject *obj, Bool_t replace /* = kFALSE */)
205205
if (replace && obj->GetName() && obj->GetName()[0]) {
206206
TObject *old;
207207
while (nullptr != (old = GetList()->FindObject(obj->GetName()))) {
208+
if (old == obj) return;
208209
Warning("Append","Replacing existing %s: %s (Potential memory leak).",
209210
obj->IsA()->GetName(),obj->GetName());
210211
ROOT::DirAutoAdd_t func = old->IsA()->GetDirectoryAutoAdd();

0 commit comments

Comments
 (0)