[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 11 14:37:18 PDT 2024
================
@@ -127,16 +133,85 @@ std::string getFormatString() {
// GetMainExecutable (since some platforms don't support taking the
// address of main, and some platforms can't implement GetMainExecutable
// without being given the address of a function in the main executable).
-std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
+std::string getExecutablePath(const char *Argv0, void *MainAddr) {
return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
}
+llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
+ std::error_code Code;
+ llvm::SmallString<128> FilePath = llvm::SmallString<128>(UserAssetPath);
+ for (auto DirIt = llvm::sys::fs::directory_iterator(UserAssetPath, Code),
+ DirEnd = llvm::sys::fs::directory_iterator();
+ !Code && DirIt != DirEnd; DirIt.increment(Code)) {
+ FilePath = llvm::SmallString<128>(DirIt->path());
----------------
ilovepi wrote:
You can either directly assign to an `std::string` or by using the `.assign()` method. I think this will have at least 1 extra copy by constructing the small string and then assigning it through the implicit conversion from `SmallString<T>` to `StringRef`.
```suggestion
FilePath = DirIt->path();
```
https://github.com/llvm/llvm-project/pull/94717
More information about the cfe-commits
mailing list