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

EnsureCapacity can throw if called against sparse mode array #746

Merged
merged 1 commit into from Jun 8, 2020

Conversation

lahma
Copy link
Collaborator

@lahma lahma commented Jun 8, 2020

fixes #745

{
const string code = @"
let arr = [];
for (let i = 0; i < 10000; i++) arr.push(i);
Copy link
Owner

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 ;)

@@ -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)
Copy link
Owner

Choose a reason for hiding this comment

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

I understand that the capacity doubles?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

@lahma lahma merged commit 293161f into sebastienros:dev Jun 8, 2020
@lahma lahma deleted the bugs/ensure-capacity-again-sparse branch June 8, 2020 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NullReferenceException for large amount of splice
2 participants