-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change BitHelper in System.Collections to be a ref struct
Simplifies BitHelper, basing it on span instead of having to accomodate both pointers and arrays, and avoids allocating the BitHelper instance. We now also clear the input optionally. Commit migrated from dotnet/corefx@82ce02d
- Loading branch information
1 parent
8fd85a5
commit eb67f75
Showing
3 changed files
with
37 additions
and
165 deletions.
There are no files selected for viewing
This file contains 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1449,17 +1449,10 @@ private unsafe ElementCount CheckUniqueAndUnfoundElements(IEnumerable<T> other, | |
int originalLastIndex = Count; | ||
int intArrayLength = BitHelper.ToIntArrayLength(originalLastIndex); | ||
|
||
BitHelper bitHelper; | ||
if (intArrayLength <= StackAllocThreshold) | ||
{ | ||
int* bitArrayPtr = stackalloc int[intArrayLength]; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stephentoub
Author
Member
|
||
bitHelper = new BitHelper(bitArrayPtr, intArrayLength); | ||
} | ||
else | ||
{ | ||
int[] bitArray = new int[intArrayLength]; | ||
bitHelper = new BitHelper(bitArray, intArrayLength); | ||
} | ||
Span<int> span = stackalloc int[StackAllocThreshold]; | ||
BitHelper bitHelper = intArrayLength <= StackAllocThreshold ? | ||
new BitHelper(span.Slice(0, intArrayLength), clear: true) : | ||
new BitHelper(new int[intArrayLength], clear: false); | ||
|
||
// count of items in other not found in this | ||
int UnfoundCount = 0; | ||
|
@stephentoub I think the unsafe keyword can be removed from this method now the pointer is changed to Span. Probably not very important but thought I'd let you know anyway.