Skip to content

Commit

Permalink
Avoid allocating unused prefix/localName in XmlCharCheckingReader.Val…
Browse files Browse the repository at this point in the history
…idateQName (#54836)
  • Loading branch information
stephentoub committed Jun 29, 2021
1 parent 72047c5 commit 39e8a6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,7 @@ private void CheckWhitespace(string value)

private void ValidateQName(string name)
{
string prefix, localName;
ValidateNames.ParseQNameThrow(name, out prefix, out localName);
ValidateNames.ParseQNameThrow(name);
}

private void ValidateQName(string prefix, string localName)
Expand Down
14 changes: 12 additions & 2 deletions src/libraries/System.Private.Xml/src/System/Xml/ValidateNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ internal static int ParseQName(string s, int offset, out int colonOffset)

/// <summary>
/// Calls parseQName and throws exception if the resulting name is not a valid QName.
/// Returns the prefix and local name parts.
/// Returns the colon offset in the name.
/// </summary>
internal static void ParseQNameThrow(string s, out string prefix, out string localName)
internal static int ParseQNameThrow(string s)
{
int colonOffset;
int len = ParseQName(s, 0, out colonOffset);
Expand All @@ -274,6 +274,16 @@ internal static void ParseQNameThrow(string s, out string prefix, out string loc
ThrowInvalidName(s, 0, len);
}

return colonOffset;
}

/// <summary>
/// Calls parseQName and throws exception if the resulting name is not a valid QName.
/// Returns the prefix and local name parts.
/// </summary>
internal static void ParseQNameThrow(string s, out string prefix, out string localName)
{
int colonOffset = ParseQNameThrow(s);
if (colonOffset != 0)
{
prefix = s.Substring(0, colonOffset);
Expand Down

0 comments on commit 39e8a6e

Please sign in to comment.