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

StreamOnSqlBytes Read/Write on Spans #86674

Merged
merged 11 commits into from
Jan 29, 2024
Merged

Conversation

hrrrrustic
Copy link
Contributor

Close #69921

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label May 23, 2023
@ghost
Copy link

ghost commented May 23, 2023

Tagging subscribers to this area: @roji, @ajcvickers
See info in area-owners.md if you want to be subscribed.

Issue Details

Close #69921

Author: hrrrrustic
Assignees: -
Labels:

area-System.Data, community-contribution

Milestone: -

// Adjust count based on data length
int count = Math.Min(buffer.Length, (int)(Length - offset));

Span<byte> span = _rgbBuf!.AsSpan((int)offset, count);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of the null-forgiving operator I'd prefer a Debug.Assert(_rgbBuf is not null), as in case it's actually null, then in CI the assert fails.
Same on other places.

Except it's really 100 % sure that it can't be null here, then ignore this comment.

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 copied all of ! from old array-based methods so I assume we are 100% sure

Copy link
Member

Choose a reason for hiding this comment

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

Please remove the ! and add the assert. The ! was ok when this was in the Read method that was also checking IsNull and throwing, but now this is reachable from an internal method that has no such check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But internal method also has IsNull check under your comment about arguments order 🤔

@hrrrrustic hrrrrustic marked this pull request as ready for review May 24, 2023 13:49
// Adjust count based on data length
int count = Math.Min(buffer.Length, (int)(Length - offset));

Span<byte> span = _rgbBuf!.AsSpan((int)offset, count);
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the ! and add the assert. The ! was ok when this was in the Read method that was also checking IsNull and throwing, but now this is reachable from an internal method that has no such check.

@danmoseley
Copy link
Member

@stephentoub do you have other feedback here?

@ajcvickers is there someone from code owners that can review it ?

@stephentoub
Copy link
Member

All test failures are known

@stephentoub stephentoub merged commit 8b082e1 into dotnet:main Jan 29, 2024
108 of 111 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Data community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SqlBytes.Stream should consider overriding Span Read/Write methods
4 participants