This repository was archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 341
Combining the T[] and OwnedBuffer<T> fields of Buffer<T> into a single object #1634
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
89b3f45
Changing Buffer<T> fields to void* and object
ahsonkhan 16182d4
Fixing Buffer Span and Retain to account for object being null
ahsonkhan 97e7263
WIP - fixing impl of retain
ahsonkhan b70cf9a
Using last bit of index to differentiate between array & ownedbuffer
ahsonkhan 690c089
Merge branch 'master' of https://github.com/dotnet/corefxlab into Buf…
ahsonkhan a29cfa8
Fixing use of index by using bitmask to ignore first bit
ahsonkhan 26b8bc6
Removing unnecessary unsafe keyword since buffer no longer contains v…
ahsonkhan 5261df6
Adding owned buffer test, use after gc collection
ahsonkhan b1af4fe
Aggressive inlining span property
ahsonkhan 3a794e4
Addressing PR comment
ahsonkhan c379c93
Tweaking test and comment
ahsonkhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
It looks like:
if ((uint)length > array.Length - (uint)start)is the same, because if (start > array.Length) -> array.Length - (uint)start less than zero and so less than any uint.Also, Why casting to uint is necessary?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean. It is the same as what? The two conditions are or'd together.
So, if
((uint)start > (uint)array.Length)is true, the second condition gets short-circuited. Only if the first condition is false, i.e. start is <= array.Length, would we run the second condition.Essentially, we need the following behaviour:
The checks in the Buffer<T> constructor implementation are inspired by Span<T>:
https://github.com/dotnet/corefx/blob/master/src/System.Memory/src/System/Span.cs#L85
I believe that is an optimization to try and help the JIT eliminate the redundant bound check. @jkotas, can you confirm?
Although, I don't see any reduction in number of instructions in the disassembly.
See #1616 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(uint)start > (uint)array.Lengthtests both a negativestartandstartbeing larger thanLengthas a negativeintcast to auintis larger thanint.MaxValue.Now it is known
startis within bounds,(uint)length > (uint)(array.Length - start))tests whetherlengthis negative or larger than available.So 4 comparisons are done in the statement, using 2 comparisons.
Not using the cast to
uintthe equivalent would be: