-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Make AsSpan(this string) ForceInline to be on par with AsSpan(this T[]) #17368
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,6 +359,7 @@ public static bool StartsWith(this ReadOnlySpan<char> span, ReadOnlySpan<char> v | |
/// <summary> | ||
/// Creates a new span over the portion of the target array. | ||
/// </summary> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static Span<T> AsSpan<T>(this T[] array, int start) | ||
{ | ||
if (array == null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Orthogonal to this PR: We should consider creating an internal static Create method on Span (in Span.Fast.cs) just like the portable span and move this AsSpan method into MemoryExtensions.cs with the rest of the overloads (since the implementation between the two would be the same). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think this is a good idea. These extra layers make the JIT work harder and tend to leave inefficiencies behind. We should not be de-optimizing fast Span just so we can share a few more lines with the slow Span. |
||
|
@@ -380,6 +381,7 @@ public static Span<T> AsSpan<T>(this T[] array, int start) | |
/// </summary> | ||
/// <param name="text">The target string.</param> | ||
/// <remarks>Returns default when <paramref name="text"/> is null.</remarks> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static ReadOnlySpan<char> AsSpan(this string text) | ||
{ | ||
if (text == null) | ||
|
@@ -397,6 +399,7 @@ public static ReadOnlySpan<char> AsSpan(this string text) | |
/// <exception cref="System.ArgumentOutOfRangeException"> | ||
/// Thrown when the specified <paramref name="start"/> index is not in range (<0 or >text.Length). | ||
/// </exception> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static ReadOnlySpan<char> AsSpan(this string text, int start) | ||
{ | ||
if (text == null) | ||
|
@@ -422,6 +425,7 @@ public static ReadOnlySpan<char> AsSpan(this string text, int start) | |
/// <exception cref="System.ArgumentOutOfRangeException"> | ||
/// Thrown when the specified <paramref name="start"/> index or <paramref name="length"/> is not in range. | ||
/// </exception> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static ReadOnlySpan<char> AsSpan(this string text, int start, int length) | ||
{ | ||
if (text == null) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to add it to this overload? I ask because it looks relatively bulky and you didn't annotate the corresponding string/int AsSpan overload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is trying to fix another non-nonsensical perf shard that we have today:
I agree that it is not obvious whether forceinlining this one is a good trade-off. We should be consistent at least - I will mark the string/int AsSpan overloads as well for consistency.