[llvm] [Support] Construct SmallVector with ArrayRef (NFC) (PR #137586)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 28 10:28:00 PDT 2025


================
@@ -74,10 +74,7 @@ ProcessInfo sys::ExecuteNoWait(StringRef Program, ArrayRef<StringRef> Args,
 
 bool sys::commandLineFitsWithinSystemLimits(StringRef Program,
                                             ArrayRef<const char *> Args) {
-  SmallVector<StringRef, 8> StringRefArgs;
-  StringRefArgs.reserve(Args.size());
-  for (const char *A : Args)
-    StringRefArgs.emplace_back(A);
+  SmallVector<StringRef, 8> StringRefArgs(Args);
   return commandLineFitsWithinSystemLimits(Program, StringRefArgs);
----------------
kazutakahirata wrote:

I am not sure if I really want to do that.  In theory, we could make `commandLineFitsWithinSystemLimits` a template function accepting both `ArrayRef<const char *>` and `ArrayRef<StringRef>`, but that would require the function to be placed in some header file.  Right now, the target-dependent code is encapsulated nicely in `llvm/lib/Support/Unix/Program.inc` and `llvm/lib/Support/Windows/Program.inc`.  I would have to move `commandLineFitsWithinSystemLimits` to the target-independent portion, namely `llvm/include/llvm/Support/Program.h`.

Maybe a better approach in the long term is to convert `argv` to an array of `StringRef` as soon as the program starts instead of delaying the conversion to `StringRef`.


https://github.com/llvm/llvm-project/pull/137586


More information about the llvm-commits mailing list