-
-
Notifications
You must be signed in to change notification settings - Fork 547
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
EnsureCapacity can throw if called against sparse mode array #746
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -648,13 +648,15 @@ private void ConvertToSparse() | |
|
||
internal void EnsureCapacity(uint capacity) | ||
{ | ||
if (capacity <= MaxDenseArrayLength && capacity > (uint) _dense.Length) | ||
if (capacity > MaxDenseArrayLength || _dense is null || capacity <= (uint) _dense.Length) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that the capacity doubles? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capacity is decided by the caller, we can grow as asked if it hasn't flipped to be dictionary (sparse) already. Usually logic asks for double the size but for example splice knows what to expect and thus was signaling specific size when algorithm is at specific point. Same like using constructor parameter, can signal known size. |
||
{ | ||
// need to grow | ||
var newArray = new PropertyDescriptor[capacity]; | ||
System.Array.Copy(_dense, newArray, _dense.Length); | ||
_dense = newArray; | ||
return; | ||
} | ||
|
||
// need to grow | ||
var newArray = new PropertyDescriptor[capacity]; | ||
System.Array.Copy(_dense, newArray, _dense.Length); | ||
_dense = newArray; | ||
} | ||
|
||
public IEnumerator<JsValue> GetEnumerator() | ||
|
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.
Showing off with these let keywords now ;)