Skip to content
Snippets Groups Projects
Commit 0e8e515f authored by Axel Naumann's avatar Axel Naumann
Browse files

[meta] TDictionary::GetDictionary() prefer class over typedef:

For `std::string`, we have both a TClass and a TDataType (as it is a typedef).
We should prefer the TClass (which fixes issue #7169), but not at the cost
of calling `TClass::GetClass()` first: that is just too slow. So instead,
check for "is it a datatype, not numeric, do we have a TClass?" which will
still prefer the TClass even if *also* a TDataType exists.

Provide documentation!
parent e6d16d66
No related branches found
No related tags found
No related merge requests found
......@@ -81,14 +81,24 @@ void TDictionary::CreateAttributeMap()
fAttributeMap = new TDictAttributeMap;
}
////////////////////////////////////////////////////////////////////////////////
/// Retrieve the type (class, fundamental type, typedef etc)
/// named "name". Returned object is either a TClass or TDataType.
/// Returns `nullptr` if the type is unknown.
TDictionary* TDictionary::GetDictionary(const char* name)
{
// Retrieve the type (class, fundamental type, typedef etc)
// named "name". Returned object is either a TClass or TDataType.
// Returns 0 if the type is unknown.
TDictionary* ret = (TDictionary*)gROOT->GetListOfTypes()->FindObject(name);
if (ret) return ret;
// Start with typedef, the query is way faster than TClass::GetClass().
if (auto* ret = (TDictionary*)gROOT->GetListOfTypes()->FindObject(name)) {
if (auto *dtRet = dynamic_cast<TDataType*>(ret)) {
if (dtRet->GetType() <= 0) {
// Not a numeric type. Is it a known class?
if (auto *clRet = TClass::GetClass(name, true))
return clRet;
}
}
return ret;
}
return TClass::GetClass(name, true);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment