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 let {log2} = require("typedObjects/utils"); | 20 let {ilog2} = require("typedObjects/utils"); |
21 | 21 |
22 function createGetter(shift, offset, view) | 22 function createGetter(shift, offset, view) |
23 { | 23 { |
24 shift = shift | 0; | 24 shift = shift | 0; |
25 offset = offset | 0; | 25 offset = offset | 0; |
26 offset >>= shift; | 26 offset >>= shift; |
27 return function() | 27 return function() |
28 { | 28 { |
29 return view[this.bufferIndex][((this.byteOffset | 0) >> shift) + offset]; | 29 return view[this.bufferIndex][((this.byteOffset | 0) >> shift) + offset]; |
30 }; | 30 }; |
31 } | 31 } |
32 | 32 |
33 function createSetter(shift, offset, view) | 33 function createSetter(shift, offset, view) |
34 { | 34 { |
35 shift = shift | 0; | 35 shift = shift | 0; |
36 offset = offset | 0; | 36 offset = offset | 0; |
37 offset >>= shift; | 37 offset >>= shift; |
38 return function(value) | 38 return function(value) |
39 { | 39 { |
40 view[this.bufferIndex][((this.byteOffset | 0) >> shift) + offset] = value; | 40 view[this.bufferIndex][((this.byteOffset | 0) >> shift) + offset] = value; |
41 }; | 41 }; |
42 } | 42 } |
43 | 43 |
44 function PrimitiveType(viewType) | 44 function PrimitiveType(viewType) |
45 { | 45 { |
46 let result = Object.create(PrimitiveType.prototype); | 46 let result = Object.create(PrimitiveType.prototype); |
47 result.viewTypes = [viewType]; | 47 result.viewTypes = [viewType]; |
48 result.byteLength = result.referenceLength = viewType.BYTES_PER_ELEMENT | 0; | 48 result.byteLength = result.referenceLength = viewType.BYTES_PER_ELEMENT | 0; |
49 | 49 |
50 let offsetShift = log2(result.byteLength) | 0; | 50 let offsetShift = ilog2(result.byteLength) | 0; |
51 result.createGetter = createGetter.bind(null, offsetShift); | 51 result.createGetter = createGetter.bind(null, offsetShift); |
52 result.createSetter = createSetter.bind(null, offsetShift); | 52 result.createSetter = createSetter.bind(null, offsetShift); |
53 Object.freeze(result); | 53 Object.freeze(result); |
54 return result; | 54 return result; |
55 } | 55 } |
56 | 56 |
57 exports.uint8 = exports.boolean = new PrimitiveType(Uint8Array); | 57 exports.uint8 = exports.boolean = new PrimitiveType(Uint8Array); |
58 exports.uint8clamped = new PrimitiveType(Uint8ClampedArray); | 58 exports.uint8clamped = new PrimitiveType(Uint8ClampedArray); |
59 exports.int8 = new PrimitiveType(Int8Array); | 59 exports.int8 = new PrimitiveType(Int8Array); |
60 exports.uint16 = new PrimitiveType(Uint16Array); | 60 exports.uint16 = new PrimitiveType(Uint16Array); |
61 exports.int16 = new PrimitiveType(Int16Array); | 61 exports.int16 = new PrimitiveType(Int16Array); |
62 exports.uint32 = new PrimitiveType(Uint32Array); | 62 exports.uint32 = new PrimitiveType(Uint32Array); |
63 exports.int32 = new PrimitiveType(Int32Array); | 63 exports.int32 = new PrimitiveType(Int32Array); |
64 exports.float32 = new PrimitiveType(Float32Array); | 64 exports.float32 = new PrimitiveType(Float32Array); |
65 exports.float64 = new PrimitiveType(Float64Array); | 65 exports.float64 = new PrimitiveType(Float64Array); |
LEFT | RIGHT |