Skip to content

Commit

Permalink
[metacling] Add cache when computing the TClingTypeInfo::Name
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Apr 1, 2019
1 parent e02466d commit 9e85377
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 4 additions & 5 deletions core/metacling/src/TClingTypeInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,12 @@ const char *TClingTypeInfo::Name() const
if (!IsValid()) {
return "";
}
// Note: This *must* be static because we are returning a pointer inside it!
TTHREAD_TLS_DECL( std::string, buf);
buf.clear();
if (!fNameCache.empty())
return fNameCache.c_str();

R__LOCKGUARD(gInterpreterMutex);
ROOT::TMetaUtils::GetFullyQualifiedTypeName(buf,fQualType,*fInterp);
return buf.c_str();
ROOT::TMetaUtils::GetFullyQualifiedTypeName(fNameCache, fQualType, *fInterp);
return fNameCache.c_str();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
11 changes: 11 additions & 0 deletions core/metacling/src/TClingTypeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include "clang/AST/Type.h"

#include <string>

namespace cling {
class Interpreter;
}
Expand All @@ -42,6 +44,8 @@ class TClingTypeInfo {
private:
cling::Interpreter *fInterp; //Cling interpreter, we do *not* own.
clang::QualType fQualType; //Clang qualified type we are querying.
// FIXME: Factor out in the TClingGenericInfo or a similar concept.
mutable std::string fNameCache;

public:

Expand All @@ -53,6 +57,13 @@ class TClingTypeInfo {

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

TClingTypeInfo(TClingTypeInfo& rhs)
{
fInterp = rhs.fInterp;
fQualType = rhs.fQualType;
fNameCache = ""; // we must not copy the cache.
}

cling::Interpreter *GetInterpreter() const { return fInterp; }

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

0 comments on commit 9e85377

Please sign in to comment.