llvm::Record::isSubClassOf(StringRef Name) constructs a new std::string

llvm::Record::isSubClassOf(StringRef Name) looks like this:

bool isSubClassOf(StringRef Name) const {
for (const auto &SCPair : SuperClasses) {
if (SCPair.first->getNameInitAsString() == Name)

return true;
}
return false;
}

Where getNameInitAsString copy constructs a new std::string. We’re only using that temporary in a comparison. Is there a better way?

This function is called quite frequently, so it becomes costly.