Skip to content

Commit

Permalink
Fixing v8 deopt with SparseQueueSet
Browse files Browse the repository at this point in the history
Some methods were working but making out of bounds
hits on the dense array which causes deopts.
Fixes #145
  • Loading branch information
Yomguithereal committed Dec 5, 2020
1 parent 69f975f commit 2980a12
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions sparse-queue-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ SparseQueueSet.prototype.has = function(member) {

var index = this.sparse[member];

var inBounds = (index >= this.start) ?
(index < (this.start + this.size)) :
(index < ((this.start + this.size) % this.capacity));
var inBounds = (
index < this.capacity &&
(
index >= this.start &&
index < this.start + this.size
) ||
(
index < ((this.start + this.size) % this.capacity)
)
);

return (
inBounds &&
Expand All @@ -67,12 +74,21 @@ SparseQueueSet.prototype.has = function(member) {
SparseQueueSet.prototype.enqueue = function(member) {
var index = this.sparse[member];

var inBounds = (index >= this.start) ?
(index < (this.start + this.size)) :
(index < ((this.start + this.size) % this.capacity));

if (this.size !== 0 && inBounds && this.dense[index] === member)
return this;
if (this.size !== 0) {
var inBounds = (
index < this.capacity &&
(
index >= this.start &&
index < this.start + this.size
) ||
(
index < ((this.start + this.size) % this.capacity)
)
);

if (inBounds && this.dense[index] === member)
return this;
}

index = (this.start + this.size) % this.capacity;

Expand Down Expand Up @@ -103,7 +119,7 @@ SparseQueueSet.prototype.dequeue = function() {

var member = this.dense[index];

this.sparse[member] = index + 1;
this.sparse[member] = this.capacity;

return member;
};
Expand Down

0 comments on commit 2980a12

Please sign in to comment.