Small speedup, per issue 422
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 28 May 2010 15:39:11 +0000 (15:39 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 28 May 2010 15:39:11 +0000 (15:39 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1395 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/common/reedsolomon/GF256.java

index ea1f3ec..9c58275 100644 (file)
@@ -130,13 +130,10 @@ public final class GF256 {
     if (a == 0 || b == 0) {
       return 0;
     }
-    if (a == 1) {
-      return b;
-    }
-    if (b == 1) {
-      return a;
-    }
-    return expTable[(logTable[a] + logTable[b]) % 255];
+    int logSum = logTable[a] + logTable[b];
+    // index is a sped-up alternative to logSum % 255 since sum
+    // is in [0,510]. Thanks to jmsachs for the idea
+    return expTable[(logSum & 0xFF) + (logSum >>> 8)];
   }
 
 }