Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 8ad2b10

Browse files
authoredMar 8, 2018
Collapse AsSpan().Slice(...) into .AsSpan(...) (#27867)

File tree

34 files changed

+170
-170
lines changed

34 files changed

+170
-170
lines changed
 

‎src/Common/src/CoreLib/System/Globalization/CompareInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ public virtual int Compare(string string1, int offset1, int length1, string stri
506506
}
507507

508508
return CompareString(
509-
string1.AsSpan().Slice(offset1, length1),
510-
string2.AsSpan().Slice(offset2, length2),
509+
string1.AsSpan(offset1, length1),
510+
string2.AsSpan(offset2, length2),
511511
options);
512512
}
513513

@@ -531,7 +531,7 @@ internal static int CompareOrdinalIgnoreCase(string strA, int indexA, int length
531531
{
532532
Debug.Assert(indexA + lengthA <= strA.Length);
533533
Debug.Assert(indexB + lengthB <= strB.Length);
534-
return CompareOrdinalIgnoreCase(strA.AsSpan().Slice(indexA, lengthA), strB.AsSpan().Slice(indexB, lengthB));
534+
return CompareOrdinalIgnoreCase(strA.AsSpan(indexA, lengthA), strB.AsSpan(indexB, lengthB));
535535
}
536536

537537
internal static unsafe int CompareOrdinalIgnoreCase(ReadOnlySpan<char> strA, ReadOnlySpan<char> strB)

‎src/Common/src/CoreLib/System/Globalization/DateTimeParse.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ internal enum DS
331331
//
332332
////////////////////////////////////////////////////////////////////////////
333333

334-
// End NumEnd NumAmPm NumSpace NumDaySep NumTimesep MonthEnd MonthSpace MonthDSep NumDateSuff NumTimeSuff DayOfWeek YearSpace YearDateSep YearEnd TimeZone Era UTCTimeMark
334+
// End NumEnd NumAmPm NumSpace NumDaySep NumTimesep MonthEnd MonthSpace MonthDSep NumDateSuff NumTimeSuff DayOfWeek YearSpace YearDateSep YearEnd TimeZone Era UTCTimeMark
335335
private static DS[][] dateParsingStates = {
336336
// DS.BEGIN // DS.BEGIN
337337
new DS[] { DS.BEGIN, DS.ERROR, DS.TX_N, DS.N, DS.D_Nd, DS.T_Nt, DS.ERROR, DS.D_M, DS.D_M, DS.D_S, DS.T_S, DS.BEGIN, DS.D_Y, DS.D_Y, DS.ERROR, DS.BEGIN, DS.BEGIN, DS.ERROR},
@@ -713,7 +713,7 @@ private static Boolean Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, r
713713
return false;
714714
}
715715

716-
// we have the date and time separators are same and getting a year number, then change the token to YearDateSep as
716+
// we have the date and time separators are same and getting a year number, then change the token to YearDateSep as
717717
// we are sure we are not parsing time.
718718
dtok.dtt = DTT.YearDateSep;
719719
break;
@@ -1002,7 +1002,7 @@ private static Boolean Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, r
10021002
return false;
10031003
}
10041004

1005-
// we have the date and time separators are same and getting a Month name, then change the token to MonthDatesep as
1005+
// we have the date and time separators are same and getting a Month name, then change the token to MonthDatesep as
10061006
// we are sure we are not parsing time.
10071007
dtok.dtt = DTT.MonthDatesep;
10081008
break;
@@ -1212,7 +1212,7 @@ private static Boolean VerifyValidPunctuation(ref __DTString str)
12121212
// The has was un-paired
12131213
return false;
12141214
}
1215-
// Valid Hash usage: eat the hash and continue.
1215+
// Valid Hash usage: eat the hash and continue.
12161216
str.GetNext();
12171217
return true;
12181218
}
@@ -2591,7 +2591,7 @@ internal static bool TryParse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, Dat
25912591
{
25922592
if (dtok.dtt == DTT.YearEnd || dtok.dtt == DTT.YearSpace || dtok.dtt == DTT.YearDateSep)
25932593
{
2594-
// When time and date separators are same and we are hitting a year number while the first parsed part of the string was recognized
2594+
// When time and date separators are same and we are hitting a year number while the first parsed part of the string was recognized
25952595
// as part of time (and not a date) DS.T_Nt, DS.T_NNt then change the state to be a date so we try to parse it as a date instead
25962596
if (dps == DS.T_Nt)
25972597
{
@@ -2608,7 +2608,7 @@ internal static bool TryParse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, Dat
26082608
{
26092609
switch (dtok.dtt)
26102610
{
2611-
// we have the case of Serbia have dates in forms 'd.M.yyyy.' so we can expect '.' after the date parts.
2611+
// we have the case of Serbia have dates in forms 'd.M.yyyy.' so we can expect '.' after the date parts.
26122612
// changing the token to end with space instead of Date Separator will avoid failing the parsing.
26132613

26142614
case DTT.YearDateSep: dtok.dtt = atEnd ? DTT.YearEnd : DTT.YearSpace; break;
@@ -2734,7 +2734,7 @@ private static Boolean DetermineTimeZoneAdjustments(ref __DTString str, ref Date
27342734
{
27352735
if ((result.flags & ParseFlags.CaptureOffset) != 0)
27362736
{
2737-
// This is a DateTimeOffset parse, so the offset will actually be captured directly, and
2737+
// This is a DateTimeOffset parse, so the offset will actually be captured directly, and
27382738
// no adjustment is required in most cases
27392739
return DateTimeOffsetTimeZonePostProcessing(ref str, ref result, styles);
27402740
}
@@ -2810,7 +2810,7 @@ private static Boolean DetermineTimeZoneAdjustments(ref __DTString str, ref Date
28102810
// Apply validation and adjustments specific to DateTimeOffset
28112811
private static Boolean DateTimeOffsetTimeZonePostProcessing(ref __DTString str, ref DateTimeResult result, DateTimeStyles styles)
28122812
{
2813-
// For DateTimeOffset, default to the Utc or Local offset when an offset was not specified by
2813+
// For DateTimeOffset, default to the Utc or Local offset when an offset was not specified by
28142814
// the input string.
28152815
if ((result.flags & ParseFlags.TimeZoneUsed) == 0)
28162816
{
@@ -2833,7 +2833,7 @@ private static Boolean DateTimeOffsetTimeZonePostProcessing(ref __DTString str,
28332833
Int64 utcTicks = result.parsedDate.Ticks - offsetTicks;
28342834

28352835
// For DateTimeOffset, both the parsed time and the corresponding UTC value must be within the boundaries
2836-
// of a DateTime instance.
2836+
// of a DateTime instance.
28372837
if (utcTicks < DateTime.MinTicks || utcTicks > DateTime.MaxTicks)
28382838
{
28392839
result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, nameof(SR.Format_UTCOutOfRange));
@@ -3668,7 +3668,7 @@ private static DateTime GetDateTimeNow(ref DateTimeResult result, ref DateTimeSt
36683668
}
36693669
}
36703670

3671-
// assume the offset is Local
3671+
// assume the offset is Local
36723672
return DateTime.Now;
36733673
}
36743674

@@ -4218,7 +4218,7 @@ private static bool ParseByFormat(
42184218
}
42194219

42204220
// The "r" and "u" formats incorrectly quoted 'GMT' and 'Z', respectively. We cannot
4221-
// correct this mistake for DateTime.ParseExact for compatibility reasons, but we can
4221+
// correct this mistake for DateTime.ParseExact for compatibility reasons, but we can
42224222
// fix it for DateTimeOffset.ParseExact as DateTimeOffset has not been publically released
42234223
// with this issue.
42244224
if ((result.flags & ParseFlags.CaptureOffset) != 0)
@@ -5045,7 +5045,7 @@ internal bool MatchSpecifiedWords(String target, bool checkWordBoundary, ref int
50455045
{
50465046
return false;
50475047
}
5048-
if (m_info.CompareOptionIgnoreCase(Value.Slice(thisPosition, segmentLength), target.AsSpan().Slice(targetPosition, segmentLength)) != 0)
5048+
if (m_info.CompareOptionIgnoreCase(Value.Slice(thisPosition, segmentLength), target.AsSpan(targetPosition, segmentLength)) != 0)
50495049
{
50505050
return false;
50515051
}
@@ -5071,7 +5071,7 @@ internal bool MatchSpecifiedWords(String target, bool checkWordBoundary, ref int
50715071
{
50725072
return false;
50735073
}
5074-
if (m_info.CompareOptionIgnoreCase(Value.Slice(thisPosition, segmentLength), target.AsSpan().Slice(targetPosition, segmentLength)) != 0)
5074+
if (m_info.CompareOptionIgnoreCase(Value.Slice(thisPosition, segmentLength), target.AsSpan(targetPosition, segmentLength)) != 0)
50755075
{
50765076
return false;
50775077
}

‎src/Common/src/CoreLib/System/Globalization/HijriCalendar.Win32.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static int GetAdvanceHijriDate()
6969
{
7070
try
7171
{
72-
int advance = Int32.Parse(str.AsSpan().Slice(HijriAdvanceRegKeyEntry.Length), provider:CultureInfo.InvariantCulture);
72+
int advance = Int32.Parse(str.AsSpan(HijriAdvanceRegKeyEntry.Length), provider:CultureInfo.InvariantCulture);
7373
if ((advance >= MinAdvancedHijri) && (advance <= MaxAdvancedHijri))
7474
{
7575
hijriAdvance = advance;

‎src/Common/src/CoreLib/System/IO/Path.Windows.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static string GetFullPath(string path, string basePath)
8383
// Path is current drive rooted i.e. starts with \:
8484
// "\Foo" and "C:\Bar" => "C:\Foo"
8585
// "\Foo" and "\\?\C:\Bar" => "\\?\C:\Foo"
86-
combinedPath = Join(GetPathRoot(basePath.AsSpan()), path.AsSpan().Slice(1)); // Cut the separator to ensure we don't end up with two separators when joining with the root.
86+
combinedPath = Join(GetPathRoot(basePath.AsSpan()), path.AsSpan(1)); // Cut the separator to ensure we don't end up with two separators when joining with the root.
8787
}
8888
else if (length >= 2 && PathInternal.IsValidDriveChar(path[0]) && path[1] == PathInternal.VolumeSeparatorChar)
8989
{
@@ -95,7 +95,7 @@ public static string GetFullPath(string path, string basePath)
9595
// Matching root
9696
// "C:Foo" and "C:\Bar" => "C:\Bar\Foo"
9797
// "C:Foo" and "\\?\C:\Bar" => "\\?\C:\Bar\Foo"
98-
combinedPath = Join(basePath, path.AsSpan().Slice(2));
98+
combinedPath = Join(basePath, path.AsSpan(2));
9999
}
100100
else
101101
{
@@ -105,8 +105,8 @@ public static string GetFullPath(string path, string basePath)
105105
combinedPath = !PathInternal.IsDevice(basePath)
106106
? path.Insert(2, @"\")
107107
: length == 2
108-
? JoinInternal(basePath.AsSpan().Slice(0, 4), path, @"\")
109-
: JoinInternal(basePath.AsSpan().Slice(0, 4), path.AsSpan().Slice(0, 2), @"\", path.AsSpan().Slice(2));
108+
? JoinInternal(basePath.AsSpan(0, 4), path, @"\")
109+
: JoinInternal(basePath.AsSpan(0, 4), path.AsSpan(0, 2), @"\", path.AsSpan(2));
110110
}
111111
}
112112
else

‎src/Common/src/CoreLib/System/IO/PathHelper.Windows.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static int PrependDevicePathChars(ref ValueStringBuilder content, bool i
8484
buffer.Append(PathInternal.UncExtendedPathPrefix);
8585

8686
// Copy Server\Share\... over to the buffer
87-
buffer.Append(content.AsSpan().Slice(PathInternal.UncPrefixLength));
87+
buffer.Append(content.AsSpan(PathInternal.UncPrefixLength));
8888

8989
// Return the prefix difference
9090
return PathInternal.UncExtendedPrefixLength - PathInternal.UncPrefixLength;
@@ -198,7 +198,7 @@ private static string TryExpandShortFileName(ref ValueStringBuilder outputBuilde
198198
if (foundIndex < inputLength - 1)
199199
{
200200
// It was a partial find, put the non-existent part of the path back
201-
outputBuilder.Append(inputBuilder.AsSpan().Slice(foundIndex, inputBuilder.Length - foundIndex));
201+
outputBuilder.Append(inputBuilder.AsSpan(foundIndex, inputBuilder.Length - foundIndex));
202202
}
203203
}
204204
}
@@ -218,7 +218,7 @@ private static string TryExpandShortFileName(ref ValueStringBuilder outputBuilde
218218
builderToUse[PathInternal.UncExtendedPrefixLength - PathInternal.UncPrefixLength] = '\\';
219219

220220
// Strip out any added characters at the front of the string
221-
ReadOnlySpan<char> output = builderToUse.AsSpan().Slice(rootDifference);
221+
ReadOnlySpan<char> output = builderToUse.AsSpan(rootDifference);
222222

223223
string returnValue = output.EqualsOrdinal(originalPath.AsSpan())
224224
? originalPath : new string(output);

‎src/Common/src/CoreLib/System/String.Manipulation.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ public string Remove(int startIndex, int count)
897897
return result;
898898
}
899899

900-
// a remove that just takes a startindex.
900+
// a remove that just takes a startindex.
901901
public string Remove(int startIndex)
902902
{
903903
if (startIndex < 0)
@@ -1136,7 +1136,7 @@ private string ReplaceHelper(int oldValueLength, string newValue, ReadOnlySpan<i
11361136
int count = replacementIdx - thisIdx;
11371137
if (count != 0)
11381138
{
1139-
this.AsSpan().Slice(thisIdx, count).CopyTo(dstSpan.Slice(dstIdx));
1139+
this.AsSpan(thisIdx, count).CopyTo(dstSpan.Slice(dstIdx));
11401140
dstIdx += count;
11411141
}
11421142
thisIdx = replacementIdx + oldValueLength;
@@ -1148,7 +1148,7 @@ private string ReplaceHelper(int oldValueLength, string newValue, ReadOnlySpan<i
11481148

11491149
// Copy over the final non-matching portion at the end of the string.
11501150
Debug.Assert(this.Length - thisIdx == dstSpan.Length - dstIdx);
1151-
this.AsSpan().Slice(thisIdx).CopyTo(dstSpan.Slice(dstIdx));
1151+
this.AsSpan(thisIdx).CopyTo(dstSpan.Slice(dstIdx));
11521152

11531153
return dst;
11541154
}
@@ -1236,7 +1236,7 @@ private string[] SplitInternal(ReadOnlySpan<char> separators, int count, StringS
12361236
return new string[] { this };
12371237
}
12381238

1239-
string[] result = omitEmptyEntries
1239+
string[] result = omitEmptyEntries
12401240
? SplitOmitEmptyEntries(sepList, default, 1, count)
12411241
: SplitKeepEmptyEntries(sepList, default, 1, count);
12421242

@@ -1301,7 +1301,7 @@ private string[] SplitInternal(string separator, string[] separators, int count,
13011301
{
13021302
return SplitInternal(separator, count, options);
13031303
}
1304-
1304+
13051305
Span<int> sepListInitialSpan = stackalloc int[StackallocIntBufferSizeLimit];
13061306
var sepListBuilder = new ValueListBuilder<int>(sepListInitialSpan);
13071307

@@ -1311,14 +1311,14 @@ private string[] SplitInternal(string separator, string[] separators, int count,
13111311
MakeSeparatorList(separators, ref sepListBuilder, ref lengthListBuilder);
13121312
ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
13131313
ReadOnlySpan<int> lengthList = lengthListBuilder.AsSpan();
1314-
1314+
13151315
// Handle the special case of no replaces.
13161316
if (sepList.Length == 0)
13171317
{
13181318
return new string[] { this };
13191319
}
13201320

1321-
string[] result = omitEmptyEntries
1321+
string[] result = omitEmptyEntries
13221322
? SplitOmitEmptyEntries(sepList, lengthList, 0, count)
13231323
: SplitKeepEmptyEntries(sepList, lengthList, 0, count);
13241324

@@ -1341,7 +1341,7 @@ private string[] SplitInternal(string separator, int count, StringSplitOptions o
13411341
return new string[] { this };
13421342
}
13431343

1344-
string[] result = options == StringSplitOptions.RemoveEmptyEntries
1344+
string[] result = options == StringSplitOptions.RemoveEmptyEntries
13451345
? SplitOmitEmptyEntries(sepList, default, separator.Length, count)
13461346
: SplitKeepEmptyEntries(sepList, default, separator.Length, count);
13471347

@@ -1386,15 +1386,15 @@ private string[] SplitKeepEmptyEntries(ReadOnlySpan<int> sepList, ReadOnlySpan<i
13861386
}
13871387

13881388

1389-
// This function will not keep the Empty string
1389+
// This function will not keep the Empty string
13901390
private string[] SplitOmitEmptyEntries(ReadOnlySpan<int> sepList, ReadOnlySpan<int> lengthList, int defaultLength, int count)
13911391
{
13921392
Debug.Assert(count >= 2);
13931393

13941394
int numReplaces = sepList.Length;
13951395

1396-
// Allocate array to hold items. This array may not be
1397-
// filled completely in this function, we will create a
1396+
// Allocate array to hold items. This array may not be
1397+
// filled completely in this function, we will create a
13981398
// new array and copy string references to that new array.
13991399
int maxItems = (numReplaces < count) ? (numReplaces + 1) : count;
14001400
string[] splitStrings = new string[maxItems];
@@ -1555,7 +1555,7 @@ private void MakeSeparatorList(string separator, ref ValueListBuilder<int> sepLi
15551555
/// </summary>
15561556
/// <param name="separators">separator strngs</param>
15571557
/// <param name="sepListBuilder"><see cref="ValueListBuilder{T}"/> for separator indexes</param>
1558-
/// <param name="lengthListBuilder"><see cref="ValueListBuilder{T}"/> for separator length values</param>
1558+
/// <param name="lengthListBuilder"><see cref="ValueListBuilder{T}"/> for separator length values</param>
15591559
private void MakeSeparatorList(string[] separators, ref ValueListBuilder<int> sepListBuilder, ref ValueListBuilder<int> lengthListBuilder)
15601560
{
15611561
Debug.Assert(separators != null && separators.Length > 0, "separators != null && separators.Length > 0");

0 commit comments

Comments
 (0)
This repository has been archived.