@@ -88,6 +88,8 @@ In order to access the name of a class within the ROOT type system, the method T
8888#include " TThreadSlots.h"
8989#include " ThreadLocalStorage.h"
9090
91+ #include < ROOT/StringUtils.hxx>
92+
9193#include < cstdio>
9294#include < cctype>
9395#include < set>
@@ -2991,26 +2993,28 @@ TVirtualIsAProxy* TClass::GetIsAProxy() const
29912993// / (to anything) or set the `rootrc` key `Root.TClass.GetClass.AutoParsing` to
29922994// / `false`.
29932995
2994- TClass *TClass::GetClass (const char * name, Bool_t load, Bool_t silent)
2996+ TClass *TClass::GetClass (std::string_view name, Bool_t load, Bool_t silent)
29952997{
29962998 return TClass::GetClass (name, load, silent, 0 , 0 );
29972999}
29983000
2999- TClass *TClass::GetClass (const char * name, Bool_t load, Bool_t silent, size_t hint_pair_offset, size_t hint_pair_size)
3001+ TClass *TClass::GetClass (std::string_view name, Bool_t load, Bool_t silent, size_t hint_pair_offset, size_t hint_pair_size)
30003002{
3001- if (! name || !name[ 0 ] ) return nullptr ;
3003+ if (name. empty () ) return nullptr ;
30023004
3003- if (strstr ( name, " (anonymous)" )) return nullptr ;
3004- if (strstr ( name, " (unnamed)" )) return nullptr ;
3005- if (strncmp (name," class " , 6 )== 0 ) name += 6 ;
3006- if (strncmp (name," struct " , 7 )== 0 ) name += 7 ;
3005+ if (name. find ( " (anonymous)" ) != std::string_view::npos ) return nullptr ;
3006+ if (name. find ( " (unnamed)" ) != std::string_view::npos ) return nullptr ;
3007+ if (ROOT::StartsWith (name, " class " ) ) name = name. substr ( 6 ) ;
3008+ if (ROOT::StartsWith (name, " struct " ) ) name = name. substr ( 7 ) ;
30073009
30083010 if (!gROOT ->GetListOfClasses ()) return nullptr ;
30093011
3012+ std::string nameStr = std::string (name);
3013+
30103014 // FindObject will take the read lock before actually getting the
30113015 // TClass pointer so we will need not get a partially initialized
30123016 // object.
3013- TClass *cl = (TClass*)gROOT ->GetListOfClasses ()->FindObject (name );
3017+ TClass *cl = (TClass*)gROOT ->GetListOfClasses ()->FindObject (nameStr. c_str () );
30143018
30153019 // Early return to release the lock without having to execute the
30163020 // long-ish normalization.
@@ -3022,7 +3026,7 @@ TClass *TClass::GetClass(const char *name, Bool_t load, Bool_t silent, size_t hi
30223026 // Now that we got the write lock, another thread may have constructed the
30233027 // TClass while we were waiting, so we need to do the checks again.
30243028
3025- cl = (TClass*)gROOT ->GetListOfClasses ()->FindObject (name );
3029+ cl = (TClass*)gROOT ->GetListOfClasses ()->FindObject (nameStr. c_str () );
30263030 if (cl) {
30273031 if (cl->IsLoaded () || cl->TestBit (kUnloading ))
30283032 return cl;
@@ -3058,7 +3062,7 @@ TClass *TClass::GetClass(const char *name, Bool_t load, Bool_t silent, size_t hi
30583062
30593063 // To avoid spurious auto parsing, let's check if the name as-is is
30603064 // known in the TClassTable.
3061- if (DictFuncPtr_t dict = TClassTable::GetDictNorm (name )) {
3065+ if (DictFuncPtr_t dict = TClassTable::GetDictNorm (nameStr. c_str () )) {
30623066 // The name is normalized, so the result of the first search is
30633067 // authoritative.
30643068 if (!cl && !load)
@@ -3094,7 +3098,7 @@ TClass *TClass::GetClass(const char *name, Bool_t load, Bool_t silent, size_t hi
30943098 // First look at known types but without triggering any loads
30953099 {
30963100 THashTable *typeTable = dynamic_cast <THashTable *>(gROOT ->GetListOfTypes ());
3097- TDataType *type = (TDataType *)typeTable->THashTable ::FindObject (name );
3101+ TDataType *type = (TDataType *)typeTable->THashTable ::FindObject (nameStr. c_str () );
30983102 if (type) {
30993103 if (type->GetType () > 0 )
31003104 // This is a numerical type
@@ -3282,13 +3286,13 @@ TClass *TClass::GetClass(const char *name, Bool_t load, Bool_t silent, size_t hi
32823286 gInterpreter ->GetInterpreterTypeName (normalizedName.c_str (), alternative, kTRUE );
32833287 if (alternative.empty ())
32843288 return nullptr ;
3285- const char * altname = alternative. c_str () ;
3286- if (strncmp (altname, " std::" , 5 ) == 0 ) {
3289+ std::string_view altname = alternative;
3290+ if (ROOT::StartsWith (altname, " std::" ) ) {
32873291 // For namespace (for example std::__1), GetInterpreterTypeName does
32883292 // not strip std::, so we must do it explicitly here.
3289- altname += 5 ;
3293+ altname = altname. substr ( 5 ) ;
32903294 }
3291- if (altname != normalizedName && strcmp ( altname, name) != 0 ) {
3295+ if (altname != normalizedName && altname != name ) {
32923296 // altname now contains the full name of the class including a possible
32933297 // namespace if there has been a using namespace statement.
32943298
0 commit comments