ModernUO/Projects/Server/Buffers
Kamron Batman 872de8d095
fix: Optimizes GetString to eliminate allocations (#2154)
### Summary

* Optimized GetString by eliminating the intermediate string allocation.

** Note **: Encoding.GetChars() is still really inefficient, especially when strings are not aligned or have regular ascii/unicode characters. Thankfully we generally don't have to worry about these odd edge cases, but if they happen then GetChars can allocate hundreds of bytes.


This is a benchmark for just the related changes. NonSpecial are just ascii characters, while the other tests include control codes.
```cs
| Method                         | Mean     | Error   | StdDev  | Gen0   | Allocated |
|------------------------------- |---------:|--------:|--------:|-------:|----------:|
| GetString                      | 306.7 ns | 5.96 ns | 6.86 ns | 0.0124 |     200 B |
| GetStringNotSpecial            | 257.0 ns | 4.83 ns | 4.52 ns | 0.0114 |     184 B |
| GetStringSpanHelpers           | 166.4 ns | 3.26 ns | 3.48 ns |      - |         - |
| GetStringSpanHelpersNotSpecial | 137.3 ns | 1.57 ns | 1.22 ns |      - |         - |
```
2025-04-12 12:42:15 -07:00
..
PooledArraySpanFormattable.cs chore: Updates copyright (#1448) 2023-08-09 09:09:26 -07:00
RawInterpolatedStringHandler.cs feat: Adds optimized dynamic/static layout gumps (#1652) 2024-04-25 22:40:30 -07:00
SpanReader.cs fix: Fixes reading incoming string packets (#1819) 2024-06-03 14:49:26 -07:00
SpanWriter.cs fix: Improves STArray and SpanWriter with packets (#1736) 2024-04-21 20:44:25 -07:00
STArrayPool.cs fix: Fixes ObjectPropertyList double return issue (#1969) 2024-10-07 21:21:21 -07:00
ValueStringBuilder.cs fix: Optimizes GetString to eliminate allocations (#2154) 2025-04-12 12:42:15 -07:00