CommunityToolkit / CommunityToolkit/dotnet
Add an overload to StringPool.GetOrAdd method which accepts an interpolated string
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 400
- PR merge metrics
- No merged PRs in 30d
Description
### Overview
It would be really nice if there is an overload for the StringPool.GetOrAdd method which accepts a custom InterpolatedStringHandler. This InterpolatedStringHandler would create a ReadOnlySpanand use this to get the string from the pool without any string allocation (if available in the pool).
### API breakdown
```csharp
namespace CommunityToolkit.HighPerformance.Buffers;
class StringPool {
public string GetOrAdd(CustomInterpolatedStringHandler value);
}
```
### Usage example
```csharp
using CommunityToolkit.HighPerformance.Buffers;
for (int i = 0; i < 100; i++) {
var array = Foo();
// some code using the array;
}
static Employee[] Foo() {
var result = new Employee[100];
for (int i = 0; i < result.Length; i++) {
string name = StringPool.Shared.GetOrAdd($"Jim {i}"); // this would use the new overload
result[i] = new Employee(name, i);
}
return result;
}
record class Employee(string Name, decimal Salary);
```
### Breaking change?
No
### Alternatives
-
### Additional context
_No response_
### Help us help you
Yes, but only if others can assist
Contributor guide
Assessment
This issue has not been assessed yet.