In .NET 9 & C# 13 we can use spans inside async methods

This commit is contained in:
Thorsten Sommer 2025-03-12 18:56:57 +01:00
parent 38dc1ffc30
commit 4b3b80dc9d
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 0 additions and 23 deletions

View File

@ -315,26 +315,6 @@ public sealed class AgentDataSourceSelection (ILogger<AgentDataSourceSelection>
return [];
}
}
/// <summary>
/// Extracts the JSON list from the given text. The text may contain additional
/// information around the JSON list. The method tries to extract the JSON list
/// from the text.
/// </summary>
/// <remarks>
/// Algorithm: The method searches for the first line that contains only a '[' character.
/// Then, it searches for the first line that contains only a ']' character. The method
/// returns the text between these two lines (including the brackets). When the method
/// cannot find the JSON list, it returns an empty string.
/// <br/><br/>
/// This overload is using strings instead of spans. We can use this overload in any
/// async method. Thus, it is a wrapper around the span-based method. Yes, we are losing
/// the memory efficiency of the span-based method, but we still gain the performance
/// of the span-based method: the entire search algorithm is span-based.
/// </remarks>
/// <param name="text">The text that may contain the JSON list.</param>
/// <returns>The extracted JSON list.</returns>
private static string ExtractJson(string text) => ExtractJson(text.AsSpan()).ToString();
/// <summary>
/// Extracts the JSON list from the given text. The text may contain additional

View File

@ -319,9 +319,6 @@ public sealed class AgentRetrievalContextValidation (ILogger<AgentRetrievalConte
}
}
// A wrapper around the span version, because we need to call this method from an async context.
private static string ExtractJson(string text) => ExtractJson(text.AsSpan()).ToString();
private static ReadOnlySpan<char> ExtractJson(ReadOnlySpan<char> input)
{
//