[Lldb-commits] [lldb] 302b1b9 - Express PathMappingList::FindFile() in terms of PathMappingList::RemapPath()

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 29 15:19:01 PDT 2021


Author: Adrian Prantl
Date: 2021-06-29T15:14:31-07:00
New Revision: 302b1b97180907011aae610b9f51d4b9186c9821

URL: https://github.com/llvm/llvm-project/commit/302b1b97180907011aae610b9f51d4b9186c9821
DIFF: https://github.com/llvm/llvm-project/commit/302b1b97180907011aae610b9f51d4b9186c9821.diff

LOG: Express PathMappingList::FindFile() in terms of PathMappingList::RemapPath()

NFC.

This patch replaces the function body FindFile() with a call to
RemapPath(), since the two functions implement the same functionality.

Differential Revision: https://reviews.llvm.org/D104406

Added: 
    

Modified: 
    lldb/source/Target/PathMappingList.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/PathMappingList.cpp b/lldb/source/Target/PathMappingList.cpp
index f9d415bcf15d..8a8cc1c8ab9b 100644
--- a/lldb/source/Target/PathMappingList.cpp
+++ b/lldb/source/Target/PathMappingList.cpp
@@ -194,48 +194,12 @@ bool PathMappingList::ReverseRemapPath(const FileSpec &file, FileSpec &fixed) co
   return false;
 }
 
-llvm::Optional<FileSpec>
-PathMappingList::FindFile(const FileSpec &orig_spec) const {
-  if (m_pairs.empty())
-    return {};
-
-  std::string orig_path = orig_spec.GetPath();
-    
-  if (orig_path.empty())
-    return {};
-
-  bool orig_is_relative = orig_spec.IsRelative();
 
-  for (auto entry : m_pairs) {
-    llvm::StringRef orig_ref(orig_path);
-    llvm::StringRef prefix_ref = entry.first.GetStringRef();
-    if (orig_ref.size() < prefix_ref.size())
-      continue;
-    // We consider a relative prefix or one of just "." to
-    // mean "only apply to relative paths".
-    bool prefix_is_relative = false;
-    
-    if (prefix_ref == ".") {
-      prefix_is_relative = true;
-      // Remove the "." since it will have been removed from the
-      // FileSpec paths already.
-      prefix_ref = prefix_ref.drop_front();
-    } else {
-      FileSpec prefix_spec(prefix_ref, FileSpec::Style::native);
-      prefix_is_relative = prefix_spec.IsRelative();
-    }
-    if (prefix_is_relative != orig_is_relative)
-      continue;
+llvm::Optional<FileSpec> PathMappingList::FindFile(const FileSpec &orig_spec) const {
+  if (auto remapped = RemapPath(orig_spec.GetPath()))
+    if (FileSystem::Instance().Exists(*remapped))
+      return remapped;
 
-    if (orig_ref.consume_front(prefix_ref)) {
-      FileSpec new_spec;
-      new_spec.SetFile(entry.second.GetCString(), FileSpec::Style::native);
-      new_spec.AppendPathComponent(orig_ref);
-      if (FileSystem::Instance().Exists(new_spec))
-        return new_spec;
-    }
-  }
-  
   return {};
 }
 


        


More information about the lldb-commits mailing list