aprantl created this revision.
aprantl added reviewers: jingham, shafik, JDevlieghere, labath.
aprantl requested review of this revision.

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


https://reviews.llvm.org/D104406

Files:
  lldb/source/Target/PathMappingList.cpp


Index: lldb/source/Target/PathMappingList.cpp
===================================================================
--- lldb/source/Target/PathMappingList.cpp
+++ lldb/source/Target/PathMappingList.cpp
@@ -193,49 +193,11 @@
   return false;
 }
 
-llvm::Optional<FileSpec>
-PathMappingList::FindFile(const FileSpec &orig_spec) const {
-  FileSpec new_spec;
-  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)) {
-      new_spec.SetFile(entry.second.GetCString(), FileSpec::Style::native);
-      new_spec.AppendPathComponent(orig_ref);
-      if (FileSystem::Instance().Exists(new_spec))
-        return new_spec;
-    }
-  }
-  
-  new_spec.Clear();
   return {};
 }
 


Index: lldb/source/Target/PathMappingList.cpp
===================================================================
--- lldb/source/Target/PathMappingList.cpp
+++ lldb/source/Target/PathMappingList.cpp
@@ -193,49 +193,11 @@
   return false;
 }
 
-llvm::Optional<FileSpec>
-PathMappingList::FindFile(const FileSpec &orig_spec) const {
-  FileSpec new_spec;
-  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)) {
-      new_spec.SetFile(entry.second.GetCString(), FileSpec::Style::native);
-      new_spec.AppendPathComponent(orig_ref);
-      if (FileSystem::Instance().Exists(new_spec))
-        return new_spec;
-    }
-  }
-  
-  new_spec.Clear();
   return {};
 }
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to