Skip to content

Commit

Permalink
lib: mark items returned from freelist directly in alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Oct 5, 2018
1 parent 3d41d4f commit 5335c53
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/internal/freelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ class FreeList {
}

alloc() {
return this.list.length ?
setIsReused(this.list.pop(), true) :
setIsReused(this.ctor.apply(this, arguments), false);
let item;
if (this.list.length > 0) {
item = this.list.pop();
item[is_reused_symbol] = true;
} else {
item = this.ctor.apply(this, arguments);
item[is_reused_symbol] = false;
}
return item;
}

free(obj) {
Expand All @@ -25,11 +31,6 @@ class FreeList {
}
}

function setIsReused(item, reused) {
item[is_reused_symbol] = reused;
return item;
}

module.exports = {
FreeList,
symbols: {
Expand Down

0 comments on commit 5335c53

Please sign in to comment.