Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Use a faster comparison when enumeration filter strings don't have wildcards #324

Merged
merged 2 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
cgallred marked this conversation as resolved.
Show resolved Hide resolved
{
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