Skip to content

Conversation

@mithileshz
Copy link
Contributor

Use MemoryExtensions to check that the expected and actual are equal.

Fixes #3829

@OsirisTerje
Copy link
Member

@stevenaw Could you review this please?

@OsirisTerje OsirisTerje requested a review from stevenaw March 21, 2024 09:26
stevenaw
stevenaw previously approved these changes Mar 23, 2024
Copy link
Member

@stevenaw stevenaw left a comment

Choose a reason for hiding this comment

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

Looks great to me! Thanks for your contribution @mithileshz

@stevenaw stevenaw dismissed their stale review March 23, 2024 00:30

Missed something

Copy link
Member

@stevenaw stevenaw left a comment

Choose a reason for hiding this comment

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

Thanks @mithileshz ! Sorry for the false approval earlier.
This looks really great, but I left one minor suggestion here out of abundance of caution.


if (MemoryExtensions.SequenceEqual<byte>(bufferExpected, bufferActual))
{
readByte += BUFFER_SIZE;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
readByte += BUFFER_SIZE;
readByte += readActual;

Sorry, I had missed this in my first pass. It's a bit of a nitpick, but I think it may be safer here to increment by readActual here. It's possible for fewer than BUFFER_SIZE bytes to be read in and 99% of the time it likely won't matter as it's simply because it's near the end of the stream. For some streams like NetworkStream however, it may matter if the reason is that there simply aren't more bytes to read from the network that moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for pointing that out @mithileshz ! Good point, I can see why you approached your PR this way then. Given the current code also advances it by BUFFER_SIZE and has been fine for 15 years then I think the PR is also great in it's current state too.

Happy to merge it as-is or to wait if you'd prefer to push another changeset. How would you like to proceed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll leave the decision up to you as the maintainer of the repository :)

If we go with the approach for changing it, I would think we need to add a test for it with the newer changes and verify it works for existing scenarios. I don't mind doing it but I would prefer to do it in a separate changeset in case the change causes a regression and would make it easy to roll back the change.

Let me know what you think

Copy link
Member

Choose a reason for hiding this comment

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

@mithileshz I'd like to merge this as-is, it's always nice when a PR lands :)
I really like your proposed approach though, and we'd definitely appreciate a follow-up PR if you wanted to do it. 🙂

@stevenaw stevenaw merged commit 328dc52 into nunit:master Mar 23, 2024
@stevenaw
Copy link
Member

stevenaw commented Mar 23, 2024

Thanks for your contribution in this PR @mithileshz !

EDIT: As I said above, we'd happily accept a follow-up PR too if you wanted to pursue the BUFFER_SIZE changes discussed above

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.

Consider optimizing StreamsComparer for happy path

3 participants