[lld] r334518 - Refactor ExecuteAndWait to take StringRefs.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 12 10:43:52 PDT 2018


Author: zturner
Date: Tue Jun 12 10:43:52 2018
New Revision: 334518

URL: http://llvm.org/viewvc/llvm-project?rev=334518&view=rev
Log:
Refactor ExecuteAndWait to take StringRefs.

This simplifies some code which had StringRefs to begin with, and
makes other code more complicated which had const char* to begin
with.

In the end, I think this makes for a more idiomatic and platform
agnostic API.  Not all platforms launch process with null terminated
c-string arrays for the environment pointer and argv, but the api
was designed that way because it allowed easy pass-through for
posix-based platforms.  There's a little additional overhead now
since on posix based platforms we'll be takign StringRefs which
were constructed from null terminated strings and then copying
them to null terminate them again, but from a readability and
usability standpoint of the API user, I think this API signature
is strictly better.

Modified:
    lld/trunk/COFF/DriverUtils.cpp

Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=334518&r1=334517&r2=334518&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Tue Jun 12 10:43:52 2018
@@ -61,12 +61,7 @@ public:
     StringRef Exe = Saver.save(*ExeOrErr);
     Args.insert(Args.begin(), Exe);
 
-    std::vector<const char *> Vec;
-    for (StringRef S : Args)
-      Vec.push_back(S.data());
-    Vec.push_back(nullptr);
-
-    if (sys::ExecuteAndWait(Args[0], Vec.data()) != 0)
+    if (sys::ExecuteAndWait(Args[0], Args) != 0)
       fatal("ExecuteAndWait failed: " +
             llvm::join(Args.begin(), Args.end(), " "));
   }




More information about the llvm-commits mailing list