Skip to content

Commit

Permalink
Merge pull request #324 Windows: Use a faster comparison when enumera…
Browse files Browse the repository at this point in the history
…tion filter strings don't have wildcards

Windows: Use a faster comparison when enumeration filter strings don't have wildcards
  • Loading branch information
wilbaker authored Oct 2, 2018
2 parents 94bc904 + 355ead8 commit 8dba3b4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
33 changes: 28 additions & 5 deletions GVFS/GVFS.Platform.Windows/ActiveEnumeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ namespace GVFS.Platform.Windows
{
public class ActiveEnumeration
{
private static FileNamePatternMatcher doesPatternMatch = null;
private static FileNamePatternMatcher doesWildcardPatternMatch = null;

// Use our own enumerator to avoid having to dispose anything
private ProjectedFileInfoEnumerator fileInfoEnumerator;
private FileNamePatternMatcher doesPatternMatch;

private string filterString = null;

Expand All @@ -36,12 +37,13 @@ public ProjectedFileInfo Current
}

/// <summary>
/// Sets the pattern matching delegate that will be used for file name comparisons
/// Sets the pattern matching delegate that will be used for file name comparisons when the filter
/// contains wildcards.
/// </summary>
/// <param name="patternMatcher">FileNamePatternMatcher to be used by ActiveEnumeration</param>
public static void SetPatternMatcher(FileNamePatternMatcher patternMatcher)
public static void SetWildcardPatternMatcher(FileNamePatternMatcher patternMatcher)
{
doesPatternMatch = patternMatcher;
doesWildcardPatternMatch = patternMatcher;
}

/// <summary>
Expand Down Expand Up @@ -107,15 +109,31 @@ public string GetFilterString()
return this.filterString;
}

private static bool NameMatchesNoWildcardFilter(string name, string filter)
{
return string.Equals(name, filter, System.StringComparison.OrdinalIgnoreCase);
}

private void SaveFilter(string filter)
{
if (string.IsNullOrEmpty(filter))
{
this.filterString = string.Empty;
this.doesPatternMatch = null;
}
else
{
this.filterString = filter;

if (ProjFS.Utils.DoesNameContainWildCards(this.filterString))
{
this.doesPatternMatch = doesWildcardPatternMatch;
}
else
{
this.doesPatternMatch = NameMatchesNoWildcardFilter;
}

if (this.IsCurrentValid && this.IsCurrentHidden())
{
this.MoveNext();
Expand All @@ -125,7 +143,12 @@ private void SaveFilter(string filter)

private bool IsCurrentHidden()
{
return !doesPatternMatch(this.Current.Name, this.GetFilterString());
if (this.doesPatternMatch == null)
{
return false;
}

return !this.doesPatternMatch(this.Current.Name, this.GetFilterString());
}

private void ResetEnumerator()
Expand Down
4 changes: 2 additions & 2 deletions GVFS/GVFS.Platform.Windows/WindowsFileSystemVirtualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ private void InitializeEnumerationPatternMatcher()

if (projFSPatternMatchingWorks)
{
ActiveEnumeration.SetPatternMatcher(Utils.IsFileNameMatch);
ActiveEnumeration.SetWildcardPatternMatcher(Utils.IsFileNameMatch);
}
else
{
ActiveEnumeration.SetPatternMatcher(InternalFileNameMatchesFilter);
ActiveEnumeration.SetWildcardPatternMatcher(InternalFileNameMatchesFilter);
}

this.Context.Tracer.RelatedEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ActiveEnumerationTests

public ActiveEnumerationTests(PatternMatcherWrapper wrapper)
{
ActiveEnumeration.SetPatternMatcher(wrapper.Matcher);
ActiveEnumeration.SetWildcardPatternMatcher(wrapper.Matcher);
}

public static object[] Runners
Expand Down

0 comments on commit 8dba3b4

Please sign in to comment.