Skip to content
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

Open
wants to merge 16 commits into
base: dev/reduce-arrays
Choose a base branch
from

Conversation

ScrubN
Copy link

@ScrubN ScrubN commented Nov 10, 2023

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] to return 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 of value rather than using a variable length list.

Lastly, I believe I fixed 4 memory leaks in SKCanvas.DrawVertices, swapped out 3 SKTypeFace.ToFont calls to SKTypeFace.GetFont in SKTypeFace.GetGlyphs, and fixed a potential(?) nullptr dereference in SKPath.GetPoints. If any changed behaviour occurs in those methods as a result, that might have been my fault.

Bugs Fixed

API Changes

  • SKCanvas.cs
  • SKCodec.cs
  • SKColorFilter.cs
  • SKColorSpace.cs
  • SKColorSpaceStructs.cs
  • SKData.cs
  • SKFont.cs
  • SKMaskFilter.cs
  • SKMatrix.cs
  • SKMatrix44.cs
    • Removed some redundant null checks
  • SKPMColor.cs
  • SKPath.cs
  • SKPathEffect.cs
  • SKRoundRect.cs
    • Removed some redundant null checks
  • SKRuntimeEffect.cs
  • SKShader.cs
  • SKStream.cs
  • SKString.cs
  • SKTypeface.cs
  • SKVertices.cs
  • Util.cs
    • Swapped new T[0] for Array.Empty<T> ()
  • SKShaper
  • CanvasExtensions

Behavioral Changes

None.

Required skia PR

None.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Merged related skia PRs
  • Changes adhere to coding standard
  • Updated documentation

@ScrubN
Copy link
Author

ScrubN commented Nov 10, 2023

I'll make some tests later.

Feedback on the null-terminated LPArray/LPStr situation would be appreciated!

Copy link
Author

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?

@ScrubN ScrubN marked this pull request as ready for review November 14, 2023 06:42
@ScrubN
Copy link
Author

ScrubN commented Nov 14, 2023

Since the CI didn't run, here's a screenshot of the test results from my IDE. Was a bit of a pain to get it working since its setup for azure pipelines.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants