]> git.parisson.com Git - pdf.js.git/commitdiff
switch optimization
authornotmasteryet <async.processingjs@yahoo.com>
Sun, 14 Aug 2011 21:34:19 +0000 (16:34 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Sun, 14 Aug 2011 21:34:19 +0000 (16:34 -0500)
pdf.js

diff --git a/pdf.js b/pdf.js
index 24d602a861300dbc429ebf5e48be0961539ee91a..79ae776f64ffd68e25cd512e49ff3dbfdc05a667 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -2081,17 +2081,9 @@ var LZWStream = (function() {
         dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
         dictionaryValues[nextCode] = currentSequence[0];
         nextCode++;
-        switch (nextCode + earlyChange) {
-          case 512:
-            codeLength = 10;
-            break;
-          case 1024:
-            codeLength = 11;
-            break;
-          case 2048:
-            codeLength = 12;
-            break;
-        }
+        codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
+          codeLength : Math.min(Math.log(nextCode + earlyChange) /
+          0.6931471805599453 + 1, 12) | 0;
       }
       prevCode = code;