Relaxes murmurhash array requirement.
This commit is contained in:
parent
82e6018826
commit
791c9a7b13
@ -19,6 +19,7 @@
|
|||||||
* Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
|
* Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
|
||||||
* Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
|
* Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
|
||||||
*/
|
*/
|
||||||
|
/* globals Uint32ArrayView */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
|
|||||||
|
|
||||||
MurmurHash3_64.prototype = {
|
MurmurHash3_64.prototype = {
|
||||||
update: function MurmurHash3_64_update(input) {
|
update: function MurmurHash3_64_update(input) {
|
||||||
|
var useUint32ArrayView = false;
|
||||||
if (typeof input == 'string') {
|
if (typeof input == 'string') {
|
||||||
var data = new Uint8Array(input.length * 2);
|
var data = new Uint8Array(input.length * 2);
|
||||||
var length = 0;
|
var length = 0;
|
||||||
@ -48,18 +50,25 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
|
|||||||
data[length++] = code & 0xff;
|
data[length++] = code & 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (input instanceof Uint8Array) {
|
||||||
if (!(input instanceof Uint8Array)) {
|
|
||||||
throw new Error('Wrong data format in MurmurHash3_64_update. ' +
|
|
||||||
'Input must be a string or Uint8Array');
|
|
||||||
}
|
|
||||||
data = input;
|
data = input;
|
||||||
length = data.length;
|
length = data.length;
|
||||||
|
} else if (typeof input === 'object' && ('length' in input)) {
|
||||||
|
// processing regular arrays as well, e.g. for IE9
|
||||||
|
data = input;
|
||||||
|
length = data.length;
|
||||||
|
useUint32ArrayView = true;
|
||||||
|
} else {
|
||||||
|
throw new Error('Wrong data format in MurmurHash3_64_update. ' +
|
||||||
|
'Input must be a string or array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
var blockCounts = length >> 2;
|
var blockCounts = length >> 2;
|
||||||
var tailLength = length - blockCounts * 4;
|
var tailLength = length - blockCounts * 4;
|
||||||
var dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
|
// we don't care about endianness here
|
||||||
|
var dataUint32 = useUint32ArrayView ?
|
||||||
|
new Uint32ArrayView(data, blockCounts) :
|
||||||
|
new Uint32Array(data.buffer, 0, blockCounts);
|
||||||
var k1 = 0;
|
var k1 = 0;
|
||||||
var k2 = 0;
|
var k2 = 0;
|
||||||
var h1 = this.h1;
|
var h1 = this.h1;
|
||||||
|
@ -465,10 +465,10 @@ Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
|
|||||||
|
|
||||||
var Uint32ArrayView = (function Uint32ArrayViewClosure() {
|
var Uint32ArrayView = (function Uint32ArrayViewClosure() {
|
||||||
|
|
||||||
function Uint32ArrayView(buffer) {
|
function Uint32ArrayView(buffer, length) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
this.byteLength = buffer.length;
|
this.byteLength = buffer.length;
|
||||||
this.length = (this.byteLength >> 2);
|
this.length = length === undefined ? (this.byteLength >> 2) : length;
|
||||||
ensureUint32ArrayViewProps(this.length);
|
ensureUint32ArrayViewProps(this.length);
|
||||||
}
|
}
|
||||||
Uint32ArrayView.prototype = Object.create(null);
|
Uint32ArrayView.prototype = Object.create(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user