Skip to content

Commit

Permalink
Windows: Use a faster comparison when enumeration filter strings don'…
Browse files Browse the repository at this point in the history
…t have wildcards
  • Loading branch information
wilbaker committed Oct 2, 2018
1 parent bc5da49 commit ec71c14
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 wildcardPatternMatcher = null;

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

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;
wildcardPatternMatcher = patternMatcher;
}

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

private static bool NameMatchsNoWildcardFilter(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.patternMatcher = null;
}
else
{
this.filterString = filter;

if (ProjFS.Utils.DoesNameContainWildCards(this.filterString))
{
this.patternMatcher = wildcardPatternMatcher;
}
else
{
this.patternMatcher = NameMatchsNoWildcardFilter;
}

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.patternMatcher == null)
{
return false;
}

return !this.patternMatcher(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 ec71c14

Please sign in to comment.