Merge pull request #4590 from yurydelendik/ie9murhash

Relaxes murmurhash array requirement.
This commit is contained in:
Yury Delendik 2014-04-10 16:28:54 -05:00
commit 85c86a2fd7
2 changed files with 17 additions and 8 deletions

View File

@ -19,6 +19,7 @@
* Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
* Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
*/
/* globals Uint32ArrayView */
'use strict';
@ -35,6 +36,7 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
MurmurHash3_64.prototype = {
update: function MurmurHash3_64_update(input) {
var useUint32ArrayView = false;
if (typeof input == 'string') {
var data = new Uint8Array(input.length * 2);
var length = 0;
@ -48,18 +50,25 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
data[length++] = code & 0xff;
}
}
} else {
if (!(input instanceof Uint8Array)) {
throw new Error('Wrong data format in MurmurHash3_64_update. ' +
'Input must be a string or Uint8Array');
}
} else if (input instanceof Uint8Array) {
data = input;
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 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 k2 = 0;
var h1 = this.h1;

View File

@ -465,10 +465,10 @@ Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
var Uint32ArrayView = (function Uint32ArrayViewClosure() {
function Uint32ArrayView(buffer) {
function Uint32ArrayView(buffer, length) {
this.buffer = buffer;
this.byteLength = buffer.length;
this.length = (this.byteLength >> 2);
this.length = length === undefined ? (this.byteLength >> 2) : length;
ensureUint32ArrayViewProps(this.length);
}
Uint32ArrayView.prototype = Object.create(null);