mikependon / RepoDB

A hybrid ORM library for .NET.
Apache License 2.0
1.7k stars 125 forks source link

Using ReadonlySpan instead of String #1111

Closed SergerGood closed 1 year ago

SergerGood commented 2 years ago

Calling Substring produces a copy of the extracted substring. By using AsSpan instead of Substring we can eliminate the unnecessary string allocation.

before: изображение

after: изображение

mikependon commented 2 years ago

Thanks for this PR mate. Please leave this one open. I am weighing the importance of having a new reference to System.Memory over this small fraction of memory optimizations. Will get back to this one soon.

SergerGood commented 2 years ago

Why not?) I added it just for netstandard2.0. Netstandard2.0 is no longer being developed and is only needed for compatibility with .Net Feamework. In order to work with Span, a special package was created for the netstandard2.0. The api for working with ReadOnlySpan of chars is implemented in the .Net as part of optimization.

For example, implicit conversion CA1846: Prefer AsSpan over Substring String-like extension methods to ReadOnlySpan Epic #22434 Add methods to StringBuilder to append ReadOnlySpan #19437

What I did as part of this pull request is just the beginning) Unfortunately, until we abandon the netstandard, it will be difficult.