Skip to content

Commit 4bd5551

Browse files
committed
[core] Replace const string & with string_view in TClassEdit::CleanType
1 parent 853a3dd commit 4bd5551

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

core/foundation/inc/TClassEdit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ namespace TClassEdit {
202202

203203
void Init(TClassEdit::TInterpreterLookupHelper *helper);
204204

205-
std::string CleanType (const char *typeDesc,int mode = 0,const char **tail = nullptr);
205+
std::string CleanType (std::string_view typeDesc,int mode = 0,const char **tail = nullptr);
206206
inline bool IsArtificial(std::string_view name) { return name.find('@') != name.npos; }
207207
bool IsDefAlloc(const char *alloc, const char *classname);
208208
bool IsDefAlloc(const char *alloc, const char *keyclassname, const char *valueclassname);

core/foundation/src/TClassEdit.cxx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ int TClassEdit::GetSplit(const char *type, vector<string>& output, int &nestedLo
12861286
/// CleanType(" A<B, C< D, E> > *,F,G>") returns "A<B,C<D,E> >*"
12871287
////////////////////////////////////////////////////////////////////////////
12881288

1289-
string TClassEdit::CleanType(const char *typeDesc, int mode, const char **tail)
1289+
string TClassEdit::CleanType(std::string_view typeDesc, int mode, const char **tail)
12901290
{
12911291
constexpr static std::array<const char *, 3> remove{"class", "const", "volatile"};
12921292
constexpr static auto lengths = []() constexpr {
@@ -1297,12 +1297,13 @@ string TClassEdit::CleanType(const char *typeDesc, int mode, const char **tail)
12971297
}();
12981298

12991299
string result;
1300-
result.reserve(strlen(typeDesc)*2);
1300+
result.reserve(typeDesc.size()*2);
13011301
int kbl=1;
13021302
std::vector<char> parensStack;
1303-
const char* c;
1303+
const char* c = nullptr;
13041304

1305-
for(c=typeDesc;*c;c++) {
1305+
for(auto i = 0u; i < typeDesc.size(); ++i) {
1306+
c = typeDesc.data() + i;
13061307
if (std::isspace(c[0])) {
13071308
if (kbl) continue;
13081309
if (!isalnum(c[ 1]) && c[ 1] !='_') continue;
@@ -1328,7 +1329,7 @@ string TClassEdit::CleanType(const char *typeDesc, int mode, const char **tail)
13281329
// make sure that the 'keyword' is not part of a longer indentifier
13291330
if (isalnum(c[rlen]) || c[rlen]=='_' || c[rlen]=='$') continue;
13301331

1331-
c+=rlen-1; done = 1; break;
1332+
c+=rlen-1; i+=rlen-1; done = 1; break;
13321333
}
13331334
if (done) continue;
13341335
}

tree/ntuple/src/RFieldUtils.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ std::string GetRenormalizedDemangledTypeName(std::string_view demangledName, boo
463463
std::string ROOT::Internal::GetCanonicalTypePrefix(std::string_view typeName)
464464
{
465465
// Remove outer cv qualifiers and extra white spaces
466-
const std::string cleanedType = TClassEdit::CleanType(std::string(typeName).c_str(), /*mode=*/1);
466+
const std::string cleanedType = TClassEdit::CleanType(typeName, /*mode=*/1);
467467

468468
// Can happen when called from RFieldBase::Create() and is caught there
469469
if (cleanedType.empty())

0 commit comments

Comments
 (0)