| 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 let {uint16} = require("typedObjects/primitiveTypes"); | 20 let {uint16} = require("typedObjects/primitiveTypes"); |
|
René Jeschke
2014/05/19 08:15:28
Have you already thought about trading some CPU po
| |
| 21 | 21 |
|
tschuster
2014/05/19 11:31:29
I think a good idea would be to have "ASCII" strin
René Jeschke
2014/05/19 13:55:01
Sorry, but this doesn't work. If we plan to suppor
Wladimir Palant
2014/05/19 15:16:39
Actually, a cstring type might make sense in some
René Jeschke
2014/05/19 15:26:24
Yep, right. Just wanted to hear if you already con
| |
| 22 let string = exports.string = uint16.Array({ | 22 let string = exports.string = uint16.Array({ |
| 23 toString: function() | 23 toString: function() |
| 24 { | 24 { |
| 25 let buffer = this.getArrayBuffer(); | 25 let buffer = this.getArrayBuffer(); |
| 26 if (!buffer) | 26 if (!buffer) |
| 27 return ""; | 27 return ""; |
| 28 let array = new Uint16Array(buffer, this.arrayByteOffset, this.length); | 28 let array = new Uint16Array(buffer, this.arrayByteOffset, this.length); |
| 29 return String.fromCharCode.apply(null, array); | 29 return String.fromCharCode.apply(null, array); |
| 30 } | 30 } |
| 31 }, { | 31 }, { |
| 32 constructor: function(value, offset, length) | 32 constructor: function(value, offset, length) |
| 33 { | 33 { |
| 34 let type = typeof value; | 34 let type = typeof value; |
| 35 if (type == "number") | 35 if (type == "number") |
| 36 this.length = value | 0; | 36 this.length = value | 0; |
| 37 else if (type == "string" || (value && string.isInstance(value))) | 37 else if (type == "string" || (value && string.isInstance(value))) |
| 38 { | 38 { |
| 39 let sourceLength = value.length | 0; | 39 let sourceLength = value.length | 0; |
| 40 offset = Math.min(sourceLength, offset | 0) | 40 offset = Math.min(sourceLength, offset | 0) |
| 41 length = (typeof length == "number" ? length | 0 : sourceLength); | 41 length = (typeof length == "number" ? length | 0 : sourceLength); |
| 42 length = Math.min(length, sourceLength - offset); | 42 length = Math.min(length, sourceLength - offset); |
| 43 this.length = length; | 43 this.length = length; |
| 44 | 44 |
| 45 if (length > 0) | 45 if (length > 0) |
| 46 { | 46 { |
| 47 let dest = new Uint16Array(this.getArrayBuffer(), this.arrayByteOffset, length); | 47 let dest = new Uint16Array(this.getArrayBuffer(), this.arrayByteOffset, length); |
| 48 if (type == "string") | 48 if (type == "string") |
|
René Jeschke
2014/05/19 08:15:28
For readability and to enable error free future im
| |
| 49 { | |
| 49 for (let i = 0; i < length; i++, offset++) | 50 for (let i = 0; i < length; i++, offset++) |
| 50 dest[i] = value.charCodeAt(offset) | 0; | 51 dest[i] = value.charCodeAt(offset); |
|
tschuster
2014/05/19 11:31:29
|0 doesn't really make a difference if you are wri
| |
| 52 } | |
| 51 else | 53 else |
| 52 { | 54 { |
| 53 let src = new Uint16Array(value.getArrayBuffer(), | 55 let src = new Uint16Array(value.getArrayBuffer(), |
| 54 value.arrayByteOffset + offset * (uint16.referenceLength | 0), | 56 value.arrayByteOffset + offset * (uint16.referenceLength | 0), |
| 55 length); | 57 length); |
| 56 dest.set(src); | 58 dest.set(src); |
| 57 } | 59 } |
| 58 } | 60 } |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 }); | 63 }); |
| LEFT | RIGHT |