dom/settings/SettingsQueue.jsm
author Matt Woodrow <mwoodrow@mozilla.com>
Mon, 15 Apr 2013 18:55:34 +1200
changeset 135530 3b0cda3057dfc1a3c9a2342ad938a8a7ea6bcf32
parent 116587 5ce71981e005a52d4cb0b831ad3db9284f2fb356
permissions -rw-r--r--
Bug 859526 - Null check parent frames when wrapping preserve-3d display lists. r=roc

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

this.EXPORTED_SYMBOLS = ["Queue"];

this.Queue = function Queue() {
  this._queue = [];
  this._index = 0;
}

Queue.prototype = {
  getLength: function() { return (this._queue.length - this._index); },

  isEmpty: function() { return (this._queue.length == 0); },

  enqueue: function(item) { this._queue.push(item); },

  dequeue: function() {
    if(this.isEmpty())
      return undefined;

    var item = this._queue[this._index];
    if (++this._index * 2 >= this._queue.length){
      this._queue  = this._queue.slice(this._index);
      this._index = 0;
    }
    return item;
  }
}