[Pkg-javascript-commits] [pdf.js] 64/141: Relaxes murmurhash array requirement.

David Prévot taffit at moszumanska.debian.org
Sat Apr 19 22:40:30 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 791c9a7b1376d03ba44d823f51e52556004d0f86
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Thu Apr 10 07:55:08 2014 -0500

    Relaxes murmurhash array requirement.
---
 src/core/murmurhash3.js | 21 +++++++++++++++------
 src/shared/util.js      |  4 ++--
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/core/murmurhash3.js b/src/core/murmurhash3.js
index c2e7163..929dd3a 100644
--- a/src/core/murmurhash3.js
+++ b/src/core/murmurhash3.js
@@ -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;
diff --git a/src/shared/util.js b/src/shared/util.js
index efa578e..01e7fbf 100644
--- a/src/shared/util.js
+++ b/src/shared/util.js
@@ -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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list