Skip to content

Commit d42a2ad

Browse files
committed
[metacling] Add cache when computing the TClingTypeInfo::Name
1 parent 05dda57 commit d42a2ad

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

core/metacling/src/TClingTypeInfo.cxx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,12 @@ const char *TClingTypeInfo::Name() const
104104
if (!IsValid()) {
105105
return "";
106106
}
107-
// Note: This *must* be static because we are returning a pointer inside it!
108-
TTHREAD_TLS_DECL( std::string, buf);
109-
buf.clear();
107+
if (!fNameCache.empty())
108+
return fNameCache.c_str();
110109

111110
R__LOCKGUARD(gInterpreterMutex);
112-
ROOT::TMetaUtils::GetFullyQualifiedTypeName(buf,fQualType,*fInterp);
113-
return buf.c_str();
111+
ROOT::TMetaUtils::GetFullyQualifiedTypeName(fNameCache, fQualType, *fInterp);
112+
return fNameCache.c_str();
114113
}
115114

116115
////////////////////////////////////////////////////////////////////////////////

core/metacling/src/TClingTypeInfo.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include "clang/AST/Type.h"
2929

30+
#include <string>
31+
3032
namespace cling {
3133
class Interpreter;
3234
}
@@ -42,6 +44,8 @@ class TClingTypeInfo {
4244
private:
4345
cling::Interpreter *fInterp; //Cling interpreter, we do *not* own.
4446
clang::QualType fQualType; //Clang qualified type we are querying.
47+
// FIXME: Factor out in the TClingGenericInfo or a similar concept.
48+
mutable std::string fNameCache;
4549

4650
public:
4751

@@ -53,6 +57,13 @@ class TClingTypeInfo {
5357

5458
TClingTypeInfo(cling::Interpreter *interp, const char *name);
5559

60+
TClingTypeInfo(TClingTypeInfo& rhs)
61+
{
62+
fInterp = rhs.fInterp;
63+
fQualType = rhs.fQualType;
64+
fNameCache = ""; // we must not copy the cache.
65+
}
66+
5667
cling::Interpreter *GetInterpreter() const { return fInterp; }
5768

5869
clang::QualType GetQualType() const { return fQualType; }

0 commit comments

Comments
 (0)