Skip to content

Instantly share code, notes, and snippets.

@danielepolencic
Last active August 29, 2015 14:04
Show Gist options
  • Save danielepolencic/6f2c13b356263177ce29 to your computer and use it in GitHub Desktop.
Save danielepolencic/6f2c13b356263177ce29 to your computer and use it in GitHub Desktop.
module.exports = Foo
function Foo () {}
Foo.prototype.one = function (l) {
this.two(l);
};
Foo.prototype.two = function (l) {
if (l % 2) {
// this.three(l * 1.5 + 16);
this.four(l * 1.5 + 16);
}
};
Foo.prototype.three = function (l) {
this.four(l);
};
Foo.prototype.four = function (l) {
getCapacity(l);
}
function getCapacity (capacity) {
if (typeof capacity !== 'number') return 16;
pow2AtLeast(
Math.min(Math.max(16, capacity), 1073741824)
);
}
function pow2AtLeast (n) {
n = n >>> 0;
n = n - 1;
n = n | (n >> 1);
n = n | (n >> 2);
n = n | (n >> 4);
n = n | (n >> 8);
n = n | (n >> 16);
return n + 1;
}
module.exports = Foo
function Foo () {}
Foo.prototype.one = function (l) {
this.two(l);
};
Foo.prototype.two = function (l) {
if (l % 2) {
this.three(l * 1.5 + 16);
}
};
Foo.prototype.three = function (l) {
this.four(l);
};
Foo.prototype.four = function (l) {
getCapacity(l);
}
function getCapacity (capacity) {
if (typeof capacity !== 'number') return 16;
pow2AtLeast(
Math.min(Math.max(16, capacity), 1073741824)
);
}
function pow2AtLeast (n) {
n = n >>> 0;
n = n - 1;
n = n | (n >> 1);
n = n | (n >> 2);
n = n | (n >> 4);
n = n | (n >> 8);
n = n | (n >> 16);
return n + 1;
}
var Foo = require('./foo');
var l = 2 * 1000 * 1000;
var foo = new Foo();
while (--l) {
foo.one(l)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment