Skip to content

Commit b911d2d

Browse files
committed
lld/COFF: Simplify getOutputPath() using sys::path functions.
Also mention "basename" and "dirname" in Path.h since I tried to find these functions by looking for these strings. It might help others find them faster if the comments contain these strings. No behavior change. Differential Revision: https://reviews.llvm.org/D69458
1 parent f5e1b71 commit b911d2d

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

lld/COFF/Driver.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
104104

105105
// Drop directory components and replace extension with ".exe" or ".dll".
106106
static std::string getOutputPath(StringRef path) {
107-
auto p = path.find_last_of("\\/");
108-
StringRef s = (p == StringRef::npos) ? path : path.substr(p + 1);
109-
const char* e = config->dll ? ".dll" : ".exe";
110-
return (s.substr(0, s.rfind('.')) + e).str();
107+
return (sys::path::stem(path) + (config->dll ? ".dll" : ".exe")).str();
111108
}
112109

113110
// Returns true if S matches /crtend.?\.o$/.

llvm/include/llvm/Support/Path.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ reverse_iterator rend(StringRef path);
121121

122122
/// Remove the last component from \a path unless it is the root dir.
123123
///
124+
/// Similar to the POSIX "dirname" utility.
125+
///
124126
/// @code
125127
/// directory/filename.cpp => directory/
126128
/// directory/ => directory
@@ -295,7 +297,7 @@ StringRef parent_path(StringRef path, Style style = Style::native);
295297
///
296298
/// @param path Input path.
297299
/// @result The filename part of \a path. This is defined as the last component
298-
/// of \a path.
300+
/// of \a path. Similar to the POSIX "basename" utility.
299301
StringRef filename(StringRef path, Style style = Style::native);
300302

301303
/// Get stem.

0 commit comments

Comments
 (0)