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

Commit 3632a51

Browse files
authored
Make AsSpan(this string) ForceInline to be on par with AsSpan(this T[]) (#17368)
1 parent c05eeef commit 3632a51

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/mscorlib/shared/System/MemoryExtensions.Fast.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ public static bool StartsWith(this ReadOnlySpan<char> span, ReadOnlySpan<char> v
359359
/// <summary>
360360
/// Creates a new span over the portion of the target array.
361361
/// </summary>
362+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
362363
public static Span<T> AsSpan<T>(this T[] array, int start)
363364
{
364365
if (array == null)
@@ -380,6 +381,7 @@ public static Span<T> AsSpan<T>(this T[] array, int start)
380381
/// </summary>
381382
/// <param name="text">The target string.</param>
382383
/// <remarks>Returns default when <paramref name="text"/> is null.</remarks>
384+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
383385
public static ReadOnlySpan<char> AsSpan(this string text)
384386
{
385387
if (text == null)
@@ -397,6 +399,7 @@ public static ReadOnlySpan<char> AsSpan(this string text)
397399
/// <exception cref="System.ArgumentOutOfRangeException">
398400
/// Thrown when the specified <paramref name="start"/> index is not in range (&lt;0 or &gt;text.Length).
399401
/// </exception>
402+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
400403
public static ReadOnlySpan<char> AsSpan(this string text, int start)
401404
{
402405
if (text == null)
@@ -422,6 +425,7 @@ public static ReadOnlySpan<char> AsSpan(this string text, int start)
422425
/// <exception cref="System.ArgumentOutOfRangeException">
423426
/// Thrown when the specified <paramref name="start"/> index or <paramref name="length"/> is not in range.
424427
/// </exception>
428+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
425429
public static ReadOnlySpan<char> AsSpan(this string text, int start, int length)
426430
{
427431
if (text == null)

src/mscorlib/shared/System/MemoryExtensions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public static ReadOnlySpan<char> TrimEnd(this ReadOnlySpan<char> span)
6868
/// </summary>
6969
/// <param name="span">The source span from which the character is removed.</param>
7070
/// <param name="trimChar">The specified character to look for and remove.</param>
71-
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
7271
public static ReadOnlySpan<char> Trim(this ReadOnlySpan<char> span, char trimChar)
7372
{
7473
return span.TrimStart(trimChar).TrimEnd(trimChar);
@@ -79,7 +78,6 @@ public static ReadOnlySpan<char> Trim(this ReadOnlySpan<char> span, char trimCha
7978
/// </summary>
8079
/// <param name="span">The source span from which the character is removed.</param>
8180
/// <param name="trimChar">The specified character to look for and remove.</param>
82-
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
8381
public static ReadOnlySpan<char> TrimStart(this ReadOnlySpan<char> span, char trimChar)
8482
{
8583
int start = 0;
@@ -1204,7 +1202,7 @@ ref MemoryMarshal.GetReference(span),
12041202
/// no larger element, the bitwise complement of <see cref="Span{T}.Length"/>.
12051203
/// </returns>
12061204
/// <exception cref="T:System.ArgumentNullException">
1207-
/// <paramref name = "comparable" /> is <see langword="null"/> .
1205+
/// <paramref name = "comparable" /> is <see langword="null"/> .
12081206
/// </exception>
12091207
[MethodImpl(MethodImplOptions.AggressiveInlining)]
12101208
public static int BinarySearch<T>(
@@ -1228,7 +1226,7 @@ public static int BinarySearch<T>(
12281226
/// no larger element, the bitwise complement of <see cref="Span{T}.Length"/>.
12291227
/// </returns>
12301228
/// <exception cref="T:System.ArgumentNullException">
1231-
/// <paramref name = "comparable" /> is <see langword="null"/> .
1229+
/// <paramref name = "comparable" /> is <see langword="null"/> .
12321230
/// </exception>
12331231
[MethodImpl(MethodImplOptions.AggressiveInlining)]
12341232
public static int BinarySearch<T, TComparable>(
@@ -1278,7 +1276,7 @@ public static int BinarySearch<T, TComparer>(
12781276
/// no larger element, the bitwise complement of <see cref="ReadOnlySpan{T}.Length"/>.
12791277
/// </returns>
12801278
/// <exception cref="T:System.ArgumentNullException">
1281-
/// <paramref name = "comparable" /> is <see langword="null"/> .
1279+
/// <paramref name = "comparable" /> is <see langword="null"/> .
12821280
/// </exception>
12831281
[MethodImpl(MethodImplOptions.AggressiveInlining)]
12841282
public static int BinarySearch<T>(
@@ -1302,7 +1300,7 @@ public static int BinarySearch<T>(
13021300
/// no larger element, the bitwise complement of <see cref="ReadOnlySpan{T}.Length"/>.
13031301
/// </returns>
13041302
/// <exception cref="T:System.ArgumentNullException">
1305-
/// <paramref name = "comparable" /> is <see langword="null"/> .
1303+
/// <paramref name = "comparable" /> is <see langword="null"/> .
13061304
/// </exception>
13071305
[MethodImpl(MethodImplOptions.AggressiveInlining)]
13081306
public static int BinarySearch<T, TComparable>(

src/mscorlib/shared/System/String.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ public static string Create<TState>(int length, TState state, SpanAction<char, T
360360
return result;
361361
}
362362

363+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
363364
public static implicit operator ReadOnlySpan<char>(string value) =>
364365
value != null ? new ReadOnlySpan<char>(ref value.GetRawStringData(), value.Length) : default;
365366

0 commit comments

Comments
 (0)