Last active
August 29, 2015 14:04
-
-
Save danielepolencic/6f2c13b356263177ce29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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