[Lldb-commits] [lldb] r298876 - In FileSpec::Equal, short-cut GetNormalizedPath.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 27 12:12:25 PDT 2017


Author: jingham
Date: Mon Mar 27 14:12:25 2017
New Revision: 298876

URL: http://llvm.org/viewvc/llvm-project?rev=298876&view=rev
Log:
In FileSpec::Equal, short-cut GetNormalizedPath.

GetNormalizedPath seems to be slow, so it's worth
shortcutting it if possible.  This change does so
when the filenames and not equal and we can tell
GetNormalizedPath would not make them equal.

Also added a test for "." final component since that
was missing.

Modified:
    lldb/trunk/source/Utility/FileSpec.cpp
    lldb/trunk/unittests/Host/FileSpecTest.cpp

Modified: lldb/trunk/source/Utility/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileSpec.cpp?rev=298876&r1=298875&r2=298876&view=diff
==============================================================================
--- lldb/trunk/source/Utility/FileSpec.cpp (original)
+++ lldb/trunk/source/Utility/FileSpec.cpp Mon Mar 27 14:12:25 2017
@@ -401,11 +401,36 @@ int FileSpec::Compare(const FileSpec &a,
 
 bool FileSpec::Equal(const FileSpec &a, const FileSpec &b, bool full,
                      bool remove_backups) {
+  static ConstString g_dot_string(".");
+  static ConstString g_dot_dot_string("..");
+
   // case sensitivity of equality test
   const bool case_sensitive = a.IsCaseSensitive() || b.IsCaseSensitive();
+  
+  bool filenames_equal = ConstString::Equals(a.m_filename, 
+                                             b.m_filename, 
+                                             case_sensitive);
+
+  // The only way two FileSpecs can be equal if their filenames are
+  // unequal is if we are removing backups and one or the other filename
+  // is a backup string:
+
+  if (!filenames_equal && !remove_backups)
+      return false;
+
+  bool last_component_is_dot = ConstString::Equals(a.m_filename, g_dot_string) 
+                               || ConstString::Equals(a.m_filename, 
+                                                      g_dot_dot_string)
+                               || ConstString::Equals(b.m_filename, 
+                                                      g_dot_string)
+                               || ConstString::Equals(b.m_filename, 
+                                                      g_dot_dot_string);
+
+  if (!filenames_equal && !last_component_is_dot)
+    return false;
 
   if (!full && (a.GetDirectory().IsEmpty() || b.GetDirectory().IsEmpty()))
-    return ConstString::Equals(a.m_filename, b.m_filename, case_sensitive);
+    return filenames_equal;
 
   if (remove_backups == false)
     return a == b;

Modified: lldb/trunk/unittests/Host/FileSpecTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/FileSpecTest.cpp?rev=298876&r1=298875&r2=298876&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/FileSpecTest.cpp (original)
+++ lldb/trunk/unittests/Host/FileSpecTest.cpp Mon Mar 27 14:12:25 2017
@@ -164,6 +164,7 @@ TEST(FileSpecTest, EqualDotsWindows) {
       {R"(C:/bar/baz)", R"(C:\foo\..\bar\baz)"},
       {R"(C:\bar)", R"(C:\foo\..\bar)"},
       {R"(C:\foo\bar)", R"(C:\foo\.\bar)"},
+      {R"(C:\foo\bar)", R"(C:\foo\bar\.)"},
   };
 
   for(const auto &test: tests) {
@@ -187,6 +188,7 @@ TEST(FileSpecTest, EqualDotsPosix) {
       {R"(/bar/baz)", R"(/foo/../bar/baz)"},
       {R"(/bar)", R"(/foo/../bar)"},
       {R"(/foo/bar)", R"(/foo/./bar)"},
+      {R"(/foo/bar)", R"(/foo/bar/.)"},
   };
 
   for(const auto &test: tests) {




More information about the lldb-commits mailing list