diff options
author | Jim Ingham <jingham@apple.com> | 2017-03-27 19:12:25 +0000 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2017-03-27 19:12:25 +0000 |
commit | 97e4f472c35d16dea12372d6ec51422216d3ad17 (patch) | |
tree | f40850e94623be3edfc55ee71db819461ec81353 /lldb/source/Utility/FileSpec.cpp | |
parent | 46a0392c61a7ed6f44c24a0f6c8493530ec08211 (diff) | |
download | bcm5719-llvm-97e4f472c35d16dea12372d6ec51422216d3ad17.tar.gz bcm5719-llvm-97e4f472c35d16dea12372d6ec51422216d3ad17.zip |
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.
llvm-svn: 298876
Diffstat (limited to 'lldb/source/Utility/FileSpec.cpp')
-rw-r--r-- | lldb/source/Utility/FileSpec.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp index 638db258545..c5fef0fdfc2 100644 --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -401,11 +401,36 @@ int FileSpec::Compare(const FileSpec &a, const FileSpec &b, bool full) { 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; |