| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Calculates the binary logarithm (position of highest bit) of an integer. | 21 * Calculates the binary logarithm (position of highest bit) of an integer. |
| 22 * Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious | 22 * Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious |
| 23 */ | 23 */ |
| 24 exports.log2 = function log2(/**Integer*/ num) /**Integer*/ | 24 exports.ilog2 = function ilog2(/**Integer*/ num) /**Integer*/ |
|
René Jeschke
2014/04/21 17:24:12
I'm not really sure is this is the right name for
Wladimir Palant
2014/04/22 15:25:05
Changed name into ilog2 but I didn't really feel l
René Jeschke
2014/04/22 15:40:34
Alright then.
| |
| 25 { | 25 { |
| 26 num = num | 0; | 26 num = num | 0; |
| 27 let result = 0; | 27 let result = 0; |
| 28 while (num >>= 1) | 28 while ((num >>= 1) > 0) |
| 29 result++; | 29 result++; |
| 30 return result; | 30 return result; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Round up a 32-bit integer to the next power of two. | 34 * Round up a 32-bit integer to the next power of two. |
| 35 * Source: See http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerO f2 | 35 * Source: See http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerO f2 |
| 36 */ | 36 */ |
| 37 exports.ceilLog2 = function ceilLog2(/**Integer*/ num) /**Integer*/ | 37 exports.nextPow2 = function nextPow2(/**Integer*/ num) /**Integer*/ |
|
René Jeschke
2014/04/21 17:24:12
See above for naming issues, maybe just call it 'n
Wladimir Palant
2014/04/22 15:25:05
Renamed into nextPow2
| |
| 38 { | 38 { |
| 39 num = num | 0; | 39 num = num | 0; |
| 40 num--; | 40 num--; |
| 41 num |= num >> 1; | 41 num |= num >> 1; |
| 42 num |= num >> 2; | 42 num |= num >> 2; |
| 43 num |= num >> 4; | 43 num |= num >> 4; |
| 44 num |= num >> 8; | 44 num |= num >> 8; |
| 45 num |= num >> 16; | 45 num |= num >> 16; |
| 46 return num + 1; | 46 return num + 1; |
| 47 }; | 47 }; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 enumerable: true | 122 enumerable: true |
| 123 }; | 123 }; |
| 124 offset += type.referenceLength; | 124 offset += type.referenceLength; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Define properties | 127 // Define properties |
| 128 Object.defineProperties(obj, descriptors); | 128 Object.defineProperties(obj, descriptors); |
| 129 | 129 |
| 130 return offset; | 130 return offset; |
| 131 }; | 131 }; |
| LEFT | RIGHT |