Skip to content

Commit 4cf7c6c

Browse files
committed
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
1 parent 1605593 commit 4cf7c6c

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

lldb/include/lldb/Target/PathMappingList.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@ class PathMappingList {
7272
/// \param[in] path
7373
/// The original source file path to try and remap.
7474
///
75-
/// \param[out] new_path
76-
/// The newly remapped filespec that is may or may not exist.
77-
///
7875
/// \return
79-
/// /b true if \a path was successfully located and \a new_path
80-
/// is filled in with a new source path, \b false otherwise.
81-
bool RemapPath(llvm::StringRef path, std::string &new_path) const;
76+
/// The remapped filespec that may or may not exist on disk.
77+
llvm::Optional<FileSpec> RemapPath(llvm::StringRef path) const;
8278
bool RemapPath(const char *, std::string &) const = delete;
8379

8480
bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const;

lldb/source/Core/Module.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,11 @@ bool Module::FindSourceFile(const FileSpec &orig_spec,
16041604
bool Module::RemapSourceFile(llvm::StringRef path,
16051605
std::string &new_path) const {
16061606
std::lock_guard<std::recursive_mutex> guard(m_mutex);
1607-
return m_source_mappings.RemapPath(path, new_path);
1607+
if (auto remapped = m_source_mappings.RemapPath(path)) {
1608+
new_path = remapped->GetPath();
1609+
return true;
1610+
}
1611+
return false;
16081612
}
16091613

16101614
void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) {

lldb/source/Target/PathMappingList.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,17 @@ void PathMappingList::Clear(bool notify) {
145145

146146
bool PathMappingList::RemapPath(ConstString path,
147147
ConstString &new_path) const {
148-
std::string remapped;
149-
if (RemapPath(path.GetStringRef(), remapped)) {
150-
new_path.SetString(remapped);
148+
if (llvm::Optional<FileSpec> remapped = RemapPath(path.GetStringRef())) {
149+
new_path.SetString(remapped->GetPath());
151150
return true;
152151
}
153152
return false;
154153
}
155154

156-
bool PathMappingList::RemapPath(llvm::StringRef path,
157-
std::string &new_path) const {
155+
llvm::Optional<FileSpec>
156+
PathMappingList::RemapPath(llvm::StringRef path) const {
158157
if (m_pairs.empty() || path.empty())
159-
return false;
158+
return {};
160159
LazyBool path_is_relative = eLazyBoolCalculate;
161160
for (const auto &it : m_pairs) {
162161
auto prefix = it.first.GetStringRef();
@@ -177,10 +176,9 @@ bool PathMappingList::RemapPath(llvm::StringRef path,
177176
}
178177
FileSpec remapped(it.second.GetStringRef());
179178
remapped.AppendPathComponent(path);
180-
new_path = remapped.GetPath();
181-
return true;
179+
return remapped;
182180
}
183-
return false;
181+
return {};
184182
}
185183

186184
bool PathMappingList::ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const {

0 commit comments

Comments
 (0)