Skip to content

Commit 2470512

Browse files
committed
Address PR feedback
1 parent fb109f3 commit 2470512

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseHeaderReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private bool ReadLine(out int startIndex, out int length)
9393

9494
int pos = _position;
9595

96-
int newline = _buffer.AsSpan(pos).IndexOf("\r\n".AsSpan());
96+
int newline = _buffer.AsSpan(pos, _length - pos).IndexOf("\r\n".AsSpan());
9797
if (newline >= 0)
9898
{
9999
startIndex = pos;

src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormatInfoScanner.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,10 @@ internal void ScanDateWord(string pattern)
538538
// the format flag.
539539
//
540540
////////////////////////////////////////////////////////////////////////////
541-
internal static FORMATFLAGS GetFormatFlagGenitiveMonth(string[] monthNames, string[] genitveMonthNames, string[] abbrevMonthNames, string[] genetiveAbbrevMonthNames)
541+
internal static FORMATFLAGS GetFormatFlagGenitiveMonth(string[] monthNames, string[] genitiveMonthNames, string[] abbrevMonthNames, string[] genitiveAbbrevMonthNames)
542542
{
543543
// If we have different names in regular and genitive month names, use genitive month flag.
544-
return (!EqualStringArrays(monthNames, genitveMonthNames) || !EqualStringArrays(abbrevMonthNames, genetiveAbbrevMonthNames))
544+
return (!monthNames.AsSpan().SequenceEqual(genitiveMonthNames) || !abbrevMonthNames.AsSpan().SequenceEqual(genitiveAbbrevMonthNames))
545545
? FORMATFLAGS.UseGenitiveMonth : 0;
546546
}
547547

@@ -590,17 +590,6 @@ internal static FORMATFLAGS GetFormatFlagUseHebrewCalendar(int calID)
590590
FORMATFLAGS.UseHebrewParsing | FORMATFLAGS.UseLeapYearMonth : 0;
591591
}
592592

593-
//-----------------------------------------------------------------------------
594-
// EqualStringArrays
595-
// compares two string arrays and return true if all elements of the first
596-
// array equals to all elements of the second array.
597-
// otherwise it returns false.
598-
//-----------------------------------------------------------------------------
599-
600-
private static bool EqualStringArrays(string[] array1, string[] array2) =>
601-
array1 == array2 ||
602-
array1.AsSpan().SequenceEqual(array2);
603-
604593
//-----------------------------------------------------------------------------
605594
// ArrayElementsHaveSpace
606595
// It checks all input array elements if any of them has space character

src/libraries/System.Private.DataContractSerialization/src/System/Xml/EncodingStreamWrapper.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ private enum SupportedEncoding { UTF8, UTF16LE, UTF16BE, None }
3131

3232
// UTF-8 is fastpath, so that's how these are stored
3333
// Compare methods adapt to Unicode.
34-
private static readonly byte[] s_encodingAttr = "encoding"u8.ToArray();
3534
private static readonly byte[] s_encodingUTF8 = "utf-8"u8.ToArray();
3635
private static readonly byte[] s_encodingUnicode = "utf-16"u8.ToArray();
3736
private static readonly byte[] s_encodingUnicodeLE = "utf-16le"u8.ToArray();
@@ -361,7 +360,8 @@ private static void CheckUTF8DeclarationEncoding(byte[] buffer, int offset, int
361360
for (i = encEq - 1; IsWhitespace(buffer[i]); i--) ;
362361

363362
// Check for encoding attribute
364-
if (!Compare(s_encodingAttr, buffer, i - s_encodingAttr.Length + 1))
363+
ReadOnlySpan<byte> encodingAttr = "encoding"u8;
364+
if (!buffer.AsSpan(i - encodingAttr.Length + 1, encodingAttr.Length).SequenceEqual(encodingAttr))
365365
{
366366
if (e != SupportedEncoding.UTF8 && expectedEnc == SupportedEncoding.None)
367367
throw new XmlException(SR.XmlDeclarationRequired);
@@ -426,9 +426,6 @@ private static bool CompareCaseInsensitive(byte[] key, byte[] buffer, int offset
426426
return true;
427427
}
428428

429-
private static bool Compare(byte[] key, byte[] buffer, int offset) =>
430-
key.AsSpan().SequenceEqual(buffer.AsSpan(offset, key.Length));
431-
432429
private static bool IsWhitespace(byte ch)
433430
{
434431
return ch == (byte)' ' || ch == (byte)'\n' || ch == (byte)'\t' || ch == (byte)'\r';

0 commit comments

Comments
 (0)