chakra-core / chakra-core/ChakraCore

Wrong begin lookup segment in JavascriptArray::DirectSetItem_Full

Open
#4,658 2 comments 0 reactions 0 assignees View on GitHub
Performance
Dominant language
JavaScript
Stars
9.3k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

In the function JavascriptArray::DirectSetItem_Full (JavaScriptArray.inl):

//Find the segment where itemIndex is present or is at the boundary
SparseArraySegment* current = (SparseArraySegment*)this->GetBeginLookupSegment(itemIndex, false);
// If it doesn't fit in current chunk (watch for overflow), start from beginning as we'll
// need the prev
if (current->left + current->size > current->left || itemIndex >= current->left + current->size)
{
current = SparseArraySegment::From(head);
}

Here it tries to use GetBeginLookupSegment to speed up the search. However, in the following statement:

if (current->left + current->size > current->left || itemIndex >= current->left + current->size)
{
current = SparseArraySegment::From(head);
}

Here current->left + current->size > current->left is always true for a normal segment, so it will always execute:
current = SparseArraySegment::From(head);
Which makes the GetBeginLookupSegment useless.

I think this is a typo here, it should be:

if (current->left + current->size < current->left || itemIndex >= current->left + current->size)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.