From: Adrian Prantl Date: Fri, 25 Jun 2021 20:49:01 +0000 (-0700) Subject: Change PathMappingList::RemapPath to return an optional result (NFC) X-Git-Tag: llvmorg-14-init~2964 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4cf7c6c6a44dba6d7f3c13059f966412df89fe75;p=platform%2Fupstream%2Fllvm.git Change PathMappingList::RemapPath to return an optional result (NFC) This is an NFC modernization refactoring that replaces the combination of a bool return + reference argument, with an Optional return value. Differential Revision: https://reviews.llvm.org/D104404 --- diff --git a/lldb/include/lldb/Target/PathMappingList.h b/lldb/include/lldb/Target/PathMappingList.h index bfc4da6..5d8e2a1 100644 --- a/lldb/include/lldb/Target/PathMappingList.h +++ b/lldb/include/lldb/Target/PathMappingList.h @@ -72,13 +72,9 @@ public: /// \param[in] path /// The original source file path to try and remap. /// - /// \param[out] new_path - /// The newly remapped filespec that is may or may not exist. - /// /// \return - /// /b true if \a path was successfully located and \a new_path - /// is filled in with a new source path, \b false otherwise. - bool RemapPath(llvm::StringRef path, std::string &new_path) const; + /// The remapped filespec that may or may not exist on disk. + llvm::Optional RemapPath(llvm::StringRef path) const; bool RemapPath(const char *, std::string &) const = delete; bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const; diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 2e8163a..6502518 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -1604,7 +1604,11 @@ bool Module::FindSourceFile(const FileSpec &orig_spec, bool Module::RemapSourceFile(llvm::StringRef path, std::string &new_path) const { std::lock_guard guard(m_mutex); - return m_source_mappings.RemapPath(path, new_path); + if (auto remapped = m_source_mappings.RemapPath(path)) { + new_path = remapped->GetPath(); + return true; + } + return false; } void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) { diff --git a/lldb/source/Target/PathMappingList.cpp b/lldb/source/Target/PathMappingList.cpp index 35e0c74..b6dbf55 100644 --- a/lldb/source/Target/PathMappingList.cpp +++ b/lldb/source/Target/PathMappingList.cpp @@ -145,18 +145,17 @@ void PathMappingList::Clear(bool notify) { bool PathMappingList::RemapPath(ConstString path, ConstString &new_path) const { - std::string remapped; - if (RemapPath(path.GetStringRef(), remapped)) { - new_path.SetString(remapped); + if (llvm::Optional remapped = RemapPath(path.GetStringRef())) { + new_path.SetString(remapped->GetPath()); return true; } return false; } -bool PathMappingList::RemapPath(llvm::StringRef path, - std::string &new_path) const { +llvm::Optional +PathMappingList::RemapPath(llvm::StringRef path) const { if (m_pairs.empty() || path.empty()) - return false; + return {}; LazyBool path_is_relative = eLazyBoolCalculate; for (const auto &it : m_pairs) { auto prefix = it.first.GetStringRef(); @@ -177,10 +176,9 @@ bool PathMappingList::RemapPath(llvm::StringRef path, } FileSpec remapped(it.second.GetStringRef()); remapped.AppendPathComponent(path); - new_path = remapped.GetPath(); - return true; + return remapped; } - return false; + return {}; } bool PathMappingList::ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const {