This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Add {RO}Span GetReference and ROMemory TryGetArray to MemoryMarshal#25789
Merged
Conversation
Author
|
@dotnet-bot test this please |
Author
|
Is this PR good to merge? |
| { | ||
| if (((OwnedMemory<T>)obj).TryGetArray(out var segment)) | ||
| { | ||
| arraySegment = new ArraySegment<T>(segment.Array, segment.Offset + (index & ReadOnlyMemory<T>.RemoveOwnedFlagBitMask), length); |
Member
There was a problem hiding this comment.
Do we need to check that the length <= segment.Length - index?
Author
There was a problem hiding this comment.
If length is greater than segment.Count (if, let's say someone implements OwnedMemory.TryGetArray incorrectly and returns a subset of the backing memory), then the ArraySegment constructor will already throw ArgumentException.
System.ArgumentException : Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
Regarding index, that only changes on a Slice operation, and we decrease the length accordingly whenever that happens. Therefore, I don't think an explicit check is necessary here.
Member
KrzysztofCwalina
left a comment
There was a problem hiding this comment.
Just one question. Otherwise looks good.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of:
https://github.com/dotnet/corefx/issues/25412
https://github.com/dotnet/corefx/issues/25615
Depends on the PR in coreclr - dotnet/coreclr#15417
cc @jkotas, @stephentoub, @KrzysztofCwalina