dom/settings/SettingsQueue.jsm
author Peter Van der Beken <peterv@propagandism.org>
Fri, 24 Aug 2012 09:32:26 -0700
changeset 109357 dc3f29a730b10ace9129d2605c7a40822ee8121f
parent 97162 df3acd8332803a52c5fd106b4f913f73f5f1d410
child 117404 658d1cf59d3817414e3549c19f0f279de750d48d
permissions -rw-r--r--
Bug 753517 part 5. Enable the list IC for new DOM bindings too. r=bz.

/* 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/. */

let EXPORTED_SYMBOLS = ["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;
  }
}