Skip to content

Commit

Permalink
Remove some enum boxing in GlobMatcher (#10051)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Jul 1, 2024
1 parent d088f1b commit a6c4b21
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Docfx.Glob/GlobMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class GlobMatcher : IEquatable<GlobMatcher>

private readonly GlobRegexItem[][] _items;
private readonly bool _negate = false;
private readonly bool _allowDotMatch = false;
private readonly bool _ignoreCase = false;
#endregion

Expand All @@ -54,6 +55,7 @@ public GlobMatcher(string pattern, GlobMatcherOptions options = DefaultOptions)

Options = options;
Raw = pattern;
_allowDotMatch = Options.HasFlag(GlobMatcherOptions.AllowDotMatch);
_ignoreCase = Options.HasFlag(GlobMatcherOptions.IgnoreCase);
_negate = ParseNegate(ref pattern, Options);
_items = Compile(pattern).ToArray();
Expand Down Expand Up @@ -172,7 +174,7 @@ private GlobRegexItem ConvertSingleGlobPart(string globPart)
// .abc will not be matched unless . is explicitly specified
if (globPart.Length > 0 && globPart[0] != '.')
{
patternStart = Options.HasFlag(GlobMatcherOptions.AllowDotMatch) ? PatternStartWithDotAllowed : PatternStartWithoutDotAllowed;
patternStart = _allowDotMatch ? PatternStartWithDotAllowed : PatternStartWithoutDotAllowed;
}

for (int i = 0; i < globPart.Length; i++)
Expand Down Expand Up @@ -295,7 +297,7 @@ private string GlobRegexItemToRegex(GlobRegexItem item)
{
return SingleStarToRegex;
}
if (Options.HasFlag(GlobMatcherOptions.AllowDotMatch))
if (_allowDotMatch)
{
// ** when dots are allowed, allows anything except .. and .
// not (^ or / followed by one or two dots followed by $ or /)
Expand Down Expand Up @@ -385,7 +387,7 @@ private bool MatchOne(string[] fileParts, GlobRegexItem[] globParts, bool matchP
break;
case GlobRegexItemType.PlainText:
StringComparison comparison = StringComparison.Ordinal;
if (Options.HasFlag(GlobMatcherOptions.IgnoreCase))
if (_ignoreCase)
{
comparison = StringComparison.OrdinalIgnoreCase;
}
Expand All @@ -408,7 +410,7 @@ private bool DisallowedMatchExists(string filePart)
{
if (filePart == "."
|| filePart == ".."
|| (!Options.HasFlag(GlobMatcherOptions.AllowDotMatch) && filePart.StartsWith(".", StringComparison.Ordinal)))
|| (!_allowDotMatch && filePart.StartsWith(".", StringComparison.Ordinal)))
{
return true;
}
Expand Down

0 comments on commit a6c4b21

Please sign in to comment.