Skip to content

Commit 58dfec7

Browse files
CopilotEgorBo
andauthored
Make String.ThrowSubstringArgumentOutOfRange static (#130103)
Makes `ThrowSubstringArgumentOutOfRange` static so it no longer takes `this`. Passing the string's `Length` as an argument instead potentially makes `this` more escape-analysis friendly since we don't pass it to `Throw*` anymore. > [!NOTE] > This PR was generated with the assistance of GitHub Copilot. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
1 parent 986fba0 commit 58dfec7

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ public string Substring(int startIndex)
22922292

22932293
if ((uint)startIndex > (uint)Length)
22942294
{
2295-
ThrowSubstringArgumentOutOfRange(startIndex, length);
2295+
ThrowSubstringArgumentOutOfRange(startIndex, length, Length);
22962296
}
22972297

22982298
return InternalSubString(startIndex, length);
@@ -2307,7 +2307,7 @@ public string Substring(int startIndex, int length)
23072307
if ((uint)startIndex > (uint)Length || (uint)length > (uint)(Length - startIndex))
23082308
#endif
23092309
{
2310-
ThrowSubstringArgumentOutOfRange(startIndex, length);
2310+
ThrowSubstringArgumentOutOfRange(startIndex, length, Length);
23112311
}
23122312

23132313
if (length == 0)
@@ -2325,11 +2325,11 @@ public string Substring(int startIndex, int length)
23252325
}
23262326

23272327
[DoesNotReturn]
2328-
private void ThrowSubstringArgumentOutOfRange(int startIndex, int length)
2328+
private static void ThrowSubstringArgumentOutOfRange(int startIndex, int length, int thisLength)
23292329
{
23302330
ArgumentOutOfRangeException.ThrowIfNegative(startIndex);
23312331

2332-
if (startIndex > Length)
2332+
if (startIndex > thisLength)
23332333
{
23342334
throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_StartIndexLargerThanLength);
23352335
}

0 commit comments

Comments
 (0)