提交 ee7b3102 编写于 作者: P Paul Harrington

Reduce allocations from string.Split in PatternMatcher constructor

上级 e4983731
......@@ -165,9 +165,19 @@ public PatternMatcher(string pattern, CultureInfo culture, bool verbatimIdentifi
_compareInfo = culture.CompareInfo;
_fullPatternSegment = new Segment(pattern, verbatimIdentifierPrefixIsWordCharacter);
if (pattern.IndexOf('.') < 0)
{
// PERF: Avoid string.Split allocations when the pattern doesn't contain a dot.
_dotSeparatedSegments = pattern.Length > 0 ? new Segment[1] { _fullPatternSegment } : SpecializedCollections.EmptyArray<Segment>();
}
else
{
_dotSeparatedSegments = pattern.Split(s_dotCharacterArray, StringSplitOptions.RemoveEmptyEntries)
.Select(text => new Segment(text.Trim(), verbatimIdentifierPrefixIsWordCharacter))
.ToArray();
}
_invalidPattern = _dotSeparatedSegments.Length == 0 || _dotSeparatedSegments.Any(s => s.IsInvalid);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册