================
@@ -71,8 +72,21 @@ Builtin::Context::getShardAndInfo(unsigned ID) const {
llvm_unreachable("Invalid target builtin shard structure!");
}
+/// Return a non-owning StringRef of the builtin's name, reconstructed into
Buf.
+static StringRef getBuiltinNameInto(const Builtin::InfosShard &Shard,
+ const Builtin::Info &BuiltinInfo,
+ SmallVectorImpl<char> &Buf) {
+ StringRef Name = (*Shard.Strings)[BuiltinInfo.Offsets.Name];
+ if (Shard.NamePrefix.empty())
+ return Name;
+ Buf.assign(Shard.NamePrefix.begin(), Shard.NamePrefix.end());
+ Buf.append(Name.begin(), Name.end());
+ return StringRef(Buf.data(), Buf.size());
+}
+
std::string Builtin::Info::getName(const Builtin::InfosShard &Shard) const {
- return (Twine(Shard.NamePrefix) + (*Shard.Strings)[Offsets.Name]).str();
+ SmallString<256> Buf;
+ return getBuiltinNameInto(Shard, *this, Buf).str();
}
----------------
jansvoboda11 wrote:
Would it make sense for callers of `Builtin::Info::getName()` to provide the
`Buf` and get a `StringRef` from this function? That would reduce allocations
even further.
https://github.com/llvm/llvm-project/pull/205162
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits