Skip to content

Instantly share code, notes, and snippets.

@ThisIsMissEm
Created October 6, 2010 18:55
Show Gist options
  • Save ThisIsMissEm/613878 to your computer and use it in GitHub Desktop.
Save ThisIsMissEm/613878 to your computer and use it in GitHub Desktop.
var fastQueue = module.exports = function fastQueue(){
this.tail = [];
this.head = Array.prototype.slice.call(arguments);
this.offset = 0;
};
fastQueue.prototype.shift = function shift() {
if (this.offset === this.head.length) {
var tmp = this.head;
tmp.length = 0;
this.head = this.tail;
this.tail = tmp;
this.offset = 0;
if (this.head.length === 0) return;
}
return this.head[this.offset++];
};
fastQueue.prototype.push = function push(item) {
return this.tail.push(item);
};
Object.defineProperty(fastQueue, "length", {
get: function() {
return this.head.length - this.offset + this.tail.length;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment