From 567dbbb0670ee5f924329d5e162056300e9893a4 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Tue, 28 Aug 2018 04:17:28 +0000 Subject: [PATCH] De-optimized Reed-Solomon generator to not store one step of precomputing multiplication tables, in preparation for next change. --- .../fastqrcodegen/ReedSolomonGenerator.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/io/nayuki/fastqrcodegen/ReedSolomonGenerator.java b/src/io/nayuki/fastqrcodegen/ReedSolomonGenerator.java index ae17275..979faec 100644 --- a/src/io/nayuki/fastqrcodegen/ReedSolomonGenerator.java +++ b/src/io/nayuki/fastqrcodegen/ReedSolomonGenerator.java @@ -110,9 +110,11 @@ final class ReedSolomonGenerator { root = multiply(root, 0x02); } - multiplies = new byte[degree][]; - for (int i = 0; i < multiplies.length; i++) - multiplies[i] = MULTIPLICATION_TABLE[coefficients[i] & 0xFF]; + multiplies = new byte[degree][256]; + for (int i = 0; i < multiplies.length; i++) { + for (int j = 0; j < 256; j++) + multiplies[i][j] = (byte)multiply(coefficients[i] & 0xFF, j); + } } @@ -151,17 +153,4 @@ final class ReedSolomonGenerator { return z; } - - private static final byte[][] MULTIPLICATION_TABLE = new byte[256][256]; - - static { - for (int i = 0; i < MULTIPLICATION_TABLE.length; i++) { - for (int j = 0; j <= i; j++) { - byte k = (byte)multiply(i, j); - MULTIPLICATION_TABLE[i][j] = k; - MULTIPLICATION_TABLE[j][i] = k; - } - } - } - }