================
@@ -780,12 +780,10 @@ static void populateSymbolInfo(SymbolInfo &I, const T *D, 
const FullComment *C,
     MangledStream << D->getNameAsString();
   // A 250 length limit was chosen since 255 is a common limit across
   // different filesystems, with a 5 character buffer for file extensions.
-  if (MangledName.size() > 250)
-    // File creation fails if the mangled name is too long, so default to the
-    // USR. We should look for a better check since filesystems differ in
-    // maximum filename length
-    I.MangledName = llvm::toStringRef(llvm::toHex(I.USR));
-  else
+  if (MangledName.size() > 250) {
+    auto SymbolID = llvm::toStringRef(llvm::toHex(I.USR)).str();
+    I.MangledName = MangledName.substr(0, 250 - SymbolID.size()) + SymbolID;
----------------
ilovepi wrote:

Its a micro optimization, but you can save 2 allocations by using Twine to 
concat in one go in the assignment. It does leave the code a bit less readable, 
but not too badly. Cant recall if the code below needs to be wrapped in 
`().str()` or not either.
```suggestion
    I.MangledName = Twine(MangledName.substr(0, 250 - SymbolID.size())) + 
llvm::toStringRef(llvm::toHex(I.USR));
```

https://github.com/llvm/llvm-project/pull/159490
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to