Skip to content

Implement Stream.Read(Span<byte>) overloads.#21356

Merged
pchote merged 1 commit into
OpenRA:bleedfrom
RoosterDragon:stream-spans
Aug 4, 2024
Merged

Implement Stream.Read(Span<byte>) overloads.#21356
pchote merged 1 commit into
OpenRA:bleedfrom
RoosterDragon:stream-spans

Conversation

@RoosterDragon

Copy link
Copy Markdown
Member

The default Stream implementation of this method has to rent an array so it can call the overload that accepts an array, and then copy the output over. This is because the array overload is required and the span overload was only added more recently.

We can avoid the overhead of this by implementing the span overload and working with the destination span directly. Do so for all classes we have that derive from Stream, and redirect their array overload to the span overload for code reuse.

The default Stream implementation of this method has to rent an array so it can call the overload that accepts an array, and then copy the output over. This is because the array overload is required and the span overload was only added more recently.

We can avoid the overhead of this by implementing the span overload and working with the destination span directly. Do so for all classes we have that derive from Stream, and redirect their array overload to the span overload for code reuse.

@pchote pchote left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM, and tested that the 4 default mods all launch to the shellmap without problems.

@PunkPun PunkPun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had also tested a bunch of formats, but didn't test videos yet

@anvilvapre anvilvapre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

untested.

var conversion = (short)(floatBuffer[i] * 32767);
buffer[offset++] = (byte)(conversion & 255);
buffer[offset++] = (byte)(conversion >> 8);
buffer[i * 2 + 0] = (byte)(conversion & 255);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial. But slower. Would then store it in a temp var.

@anvilvapre

Copy link
Copy Markdown
Contributor

Ping. Might as well merge this. Unless you still want to test videos.

@pchote

pchote commented Aug 4, 2024

Copy link
Copy Markdown
Member

I count two approvals, so merging. Tested locally that this make checks cleanly after a rebase.

@pchote pchote merged commit b313f47 into OpenRA:bleed Aug 4, 2024
@pchote

pchote commented Aug 4, 2024

Copy link
Copy Markdown
Member

@RoosterDragon RoosterDragon deleted the stream-spans branch August 4, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants