react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / har-validator / node_modules / bluebird / js / main / queue.js
81160 views"use strict";1function arrayMove(src, srcIndex, dst, dstIndex, len) {2for (var j = 0; j < len; ++j) {3dst[j + dstIndex] = src[j + srcIndex];4src[j + srcIndex] = void 0;5}6}78function Queue(capacity) {9this._capacity = capacity;10this._length = 0;11this._front = 0;12}1314Queue.prototype._willBeOverCapacity = function (size) {15return this._capacity < size;16};1718Queue.prototype._pushOne = function (arg) {19var length = this.length();20this._checkCapacity(length + 1);21var i = (this._front + length) & (this._capacity - 1);22this[i] = arg;23this._length = length + 1;24};2526Queue.prototype._unshiftOne = function(value) {27var capacity = this._capacity;28this._checkCapacity(this.length() + 1);29var front = this._front;30var i = (((( front - 1 ) &31( capacity - 1) ) ^ capacity ) - capacity );32this[i] = value;33this._front = i;34this._length = this.length() + 1;35};3637Queue.prototype.unshift = function(fn, receiver, arg) {38this._unshiftOne(arg);39this._unshiftOne(receiver);40this._unshiftOne(fn);41};4243Queue.prototype.push = function (fn, receiver, arg) {44var length = this.length() + 3;45if (this._willBeOverCapacity(length)) {46this._pushOne(fn);47this._pushOne(receiver);48this._pushOne(arg);49return;50}51var j = this._front + length - 3;52this._checkCapacity(length);53var wrapMask = this._capacity - 1;54this[(j + 0) & wrapMask] = fn;55this[(j + 1) & wrapMask] = receiver;56this[(j + 2) & wrapMask] = arg;57this._length = length;58};5960Queue.prototype.shift = function () {61var front = this._front,62ret = this[front];6364this[front] = undefined;65this._front = (front + 1) & (this._capacity - 1);66this._length--;67return ret;68};6970Queue.prototype.length = function () {71return this._length;72};7374Queue.prototype._checkCapacity = function (size) {75if (this._capacity < size) {76this._resizeTo(this._capacity << 1);77}78};7980Queue.prototype._resizeTo = function (capacity) {81var oldCapacity = this._capacity;82this._capacity = capacity;83var front = this._front;84var length = this._length;85var moveItemsCount = (front + length) & (oldCapacity - 1);86arrayMove(this, 0, this, oldCapacity, moveItemsCount);87};8889module.exports = Queue;909192