diff options
author | Kirill Bobyrev <kbobyrev@google.com> | 2020-10-21 14:18:36 +0200 |
---|---|---|
committer | Kirill Bobyrev <kbobyrev@google.com> | 2020-10-21 14:18:42 +0200 |
commit | 96685faf6dd9b044394af6f7a9d8b10fadb327b5 (patch) | |
tree | fb3ea0a21507888a5671501f3173a9568436dce9 /llvm/lib/Support/Path.cpp | |
parent | 9f5ece63ce62253321a8e8cdd3e052b5b5270b8e (diff) | |
download | llvm-96685faf6dd9b044394af6f7a9d8b10fadb327b5.zip llvm-96685faf6dd9b044394af6f7a9d8b10fadb327b5.tar.gz llvm-96685faf6dd9b044394af6f7a9d8b10fadb327b5.tar.bz2 |
[llvm] Use early exits and get rid of if-return-else-return pattern; NFC
https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D89857
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index bbc02a2..ef223ae 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -354,10 +354,9 @@ StringRef root_path(StringRef path, Style style) { if ((++pos != e) && is_separator((*pos)[0], style)) { // {C:/,//net/}, so get the first two components. return path.substr(0, b->size() + pos->size()); - } else { - // just {C:,//net}, return the first component. - return *b; } + // just {C:,//net}, return the first component. + return *b; } // POSIX style root directory. @@ -467,8 +466,7 @@ StringRef parent_path(StringRef path, Style style) { size_t end_pos = parent_path_end(path, style); if (end_pos == StringRef::npos) return StringRef(); - else - return path.substr(0, end_pos); + return path.substr(0, end_pos); } void remove_filename(SmallVectorImpl<char> &path, Style style) { @@ -581,12 +579,10 @@ StringRef stem(StringRef path, Style style) { size_t pos = fname.find_last_of('.'); if (pos == StringRef::npos) return fname; - else - if ((fname.size() == 1 && fname == ".") || - (fname.size() == 2 && fname == "..")) - return fname; - else - return fname.substr(0, pos); + if ((fname.size() == 1 && fname == ".") || + (fname.size() == 2 && fname == "..")) + return fname; + return fname.substr(0, pos); } StringRef extension(StringRef path, Style style) { @@ -594,12 +590,10 @@ StringRef extension(StringRef path, Style style) { size_t pos = fname.find_last_of('.'); if (pos == StringRef::npos) return StringRef(); - else - if ((fname.size() == 1 && fname == ".") || - (fname.size() == 2 && fname == "..")) - return StringRef(); - else - return fname.substr(pos); + if ((fname.size() == 1 && fname == ".") || + (fname.size() == 2 && fname == "..")) + return StringRef(); + return fname.substr(pos); } bool is_separator(char value, Style style) { @@ -1299,7 +1293,7 @@ Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode) { #endif return std::move(Ret); } -} +} // namespace fs -} // end namsspace sys -} // end namespace llvm +} // namespace sys +} // namespace llvm |