[PATCH] D69458: lld/COFF: Simplify getOutputPath() using sys::path functions.

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 28 07:40:22 PDT 2019


thakis added inline comments.


================
Comment at: lld/COFF/Driver.cpp:107-108
 static std::string getOutputPath(StringRef path) {
-  auto p = path.find_last_of("\\/");
-  StringRef s = (p == StringRef::npos) ? path : path.substr(p + 1);
-  const char* e = config->dll ? ".dll" : ".exe";
-  return (s.substr(0, s.rfind('.')) + e).str();
+  SmallString<128> outputPath = sys::path::filename(path);
+  sys::path::replace_extension(outputPath, config->dll ? ".dll" : ".exe");
+  return outputPath.str();
----------------
ruiu wrote:
> It seems that you can simplify this further to `sys::path::stem(path) + (config->dll ? ".dll" : ".exe")`, but I'm fine with this too.
That's even nicer, thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69458/new/

https://reviews.llvm.org/D69458





More information about the llvm-commits mailing list