-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More Span<T> and ReadOnlySpan<T> #2669
base: dev/reduce-arrays
Are you sure you want to change the base?
Conversation
…oads are still useful. Some null checks have been removed as they are immediately followed by minimum length checks, which effectively accomplish the same goal.
The length checks immediately following the null checks accomplish the same goal.
…nlySpan<char> instead of strings.
I'll make some tests later. Feedback on the null-terminated LPArray/LPStr situation would be appreciated! |
…apedText to use ReadOnlySpan<char>
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.
Is there a specific reason public Result Shape(string text, float xOffset, float yOffset, SKFont font)
uses buffer.AddUtf8
instead of buffer.AddUtf16
?
@mattleibow What steps are needed to get this PR merged into dev/reduce-arrays, then dev/reduce-arrays into main? |
This would be fantastic to include especially for rendering partial arrays like on the |
Description of Change
I have migrated many methods that previously required Arrays to use Spans instead. Additionally, a handful of methods that were previously string-only and already had the potential to be substituted by ReadOnlySpan were also converted to spans.
Some methods that previously did not use spans warranted keeping non-span overloads due to specific advantages or assumptions, such as the lack of needing to make defensive copies or the fact that strings are so versatile.
Some methods could not be migrated from array/string to span because the C++ requires that they be null-terminated. This could be solved by copying the contents of the span into a rented array and filling the rest of the array with
null
, however I wanted to discuss this change before making it.The next changes aren't strictly related to converting to spans, but I figured they were related enough to include them here. If not, I can move them to a new PR.
I changed a few
return new T[0]
toreturn Array.Empty<T> ()
to reduce pointless allocations. As far as I can tell, this does not change the behaviour of dereferencing a pointer to the array.I also changed the algorithm of
implicit operator SKRuntimeEffectUniform (float[][] value)
to make allocations linearly associated with the length ofvalue
rather than using a variable length list.Lastly, I believe I fixed 4 memory leaks in
SKCanvas.DrawVertices
, swapped out 3SKTypeFace.ToFont
calls toSKTypeFace.GetFont
inSKTypeFace.GetGlyphs
, and fixed a potential(?) nullptr dereference inSKPath.GetPoints
. If any changed behaviour occurs in those methods as a result, that might have been my fault.Bugs Fixed
Span<T>
orReadOnlySpan<T>
#2616API Changes
new T[0]
forArray.Empty<T> ()
Behavioral Changes
None.
Required skia PR
None.
PR Checklist