Skip to content

Commit

Permalink
fix unordered arrays enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
nilproject committed Dec 9, 2024
1 parent 777805b commit 249c6f5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions NiL.JS/Core/SparseArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -851,21 +851,23 @@ public IEnumerable<KeyValuePair<int, TValue>> Unordered
{
for (var i = 0; i < _navyData.Length; i++)
{
var realSegmentIndex = (int)_segmentsNavyData[i].index * SegmentSize;

if (_navyData[i].Length != 0)
{
for (var j = 0; j < _used[i]; j++)
{
yield return new KeyValuePair<int, TValue>(_navyData[i].Length is 0 ? i * SegmentSize + j : (int)_navyData[i][j].index, _values[i][j]!);
yield return new KeyValuePair<int, TValue>(_navyData[i].Length is 0 ? realSegmentIndex + j : (int)_navyData[i][j].index, _values[i][j]!);
}
}
else
{
for (var j = 0; j < _values[i].Length; j++)
{
if (i * SegmentSize + j >= _pseudoLength)
if (realSegmentIndex + j >= _pseudoLength)
break;

yield return new KeyValuePair<int, TValue>(i * SegmentSize + j, _values[i][j]!);
yield return new KeyValuePair<int, TValue>(realSegmentIndex + j, _values[i][j]!);
}
}
}
Expand Down

0 comments on commit 249c6f5

Please sign in to comment.