Code coverage report for lib/internal/freelist.js

Statements: 91.67% (11 / 12)      Branches: 75% (3 / 4)      Functions: 100% (3 / 3)      Lines: 91.67% (11 / 12)      Ignored: none     

All files » lib/internal/ » freelist.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27      174 173 173 173 173       174 2467         174 2467 2467 2467            
(function () { 'use strict';
 
// This is a free list to avoid creating so many of the same object.
exports.FreeList = function(name, max, constructor) {
  this.name = name;
  this.constructor = constructor;
  this.max = max;
  this.list = [];
};
 
 
exports.FreeList.prototype.alloc = function() {
  return this.list.length ? this.list.shift() :
                            this.constructor.apply(this, arguments);
};
 
 
exports.FreeList.prototype.free = function(obj) {
  Eif (this.list.length < this.max) {
    this.list.push(obj);
    return true;
  }
  return false;
};
 
}());