From: srowen Date: Wed, 5 Mar 2008 21:55:18 +0000 (+0000) Subject: More minor code improvements X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=0f56f9e612e46ebd4c79272933ac0881b7ba6bdb;hp=3065a8166246a727a6d910c9d24a4f52b1065390;p=zxing.git More minor code improvements git-svn-id: http://zxing.googlecode.com/svn/trunk@248 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/core/src/com/google/zxing/common/BitArray.java b/core/src/com/google/zxing/common/BitArray.java index 0d2884ca..c22fd925 100644 --- a/core/src/com/google/zxing/common/BitArray.java +++ b/core/src/com/google/zxing/common/BitArray.java @@ -27,6 +27,9 @@ public final class BitArray { private final int size; public BitArray(int size) { + if (size < 1) { + throw new IllegalArgumentException("size must be at least 1"); + } this.size = size; this.bits = makeArray(size); } diff --git a/core/src/com/google/zxing/common/reedsolomon/GF256Poly.java b/core/src/com/google/zxing/common/reedsolomon/GF256Poly.java index f5968c11..95f23c4f 100644 --- a/core/src/com/google/zxing/common/reedsolomon/GF256Poly.java +++ b/core/src/com/google/zxing/common/reedsolomon/GF256Poly.java @@ -44,16 +44,17 @@ final class GF256Poly { throw new IllegalArgumentException(); } this.field = field; - if (coefficients.length > 1 && coefficients[0] == 0) { + int coefficientsLength = coefficients.length; + if (coefficientsLength > 1 && coefficients[0] == 0) { // Leading term must be non-zero for anything except the constant polynomial "0" int firstNonZero = 1; - while (firstNonZero < coefficients.length && coefficients[firstNonZero] == 0) { + while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0) { firstNonZero++; } - if (firstNonZero == coefficients.length) { + if (firstNonZero == coefficientsLength) { this.coefficients = field.getZero().coefficients; } else { - this.coefficients = new int[coefficients.length - firstNonZero]; + this.coefficients = new int[coefficientsLength - firstNonZero]; System.arraycopy(coefficients, firstNonZero, this.coefficients, @@ -190,9 +191,8 @@ final class GF256Poly { } int size = coefficients.length; int[] product = new int[size]; - System.arraycopy(coefficients, 0, product, 0, size); for (int i = 0; i < size; i++) { - product[i] = field.multiply(product[i], scalar); + product[i] = field.multiply(coefficients[i], scalar); } return new GF256Poly(field, product); } @@ -206,9 +206,8 @@ final class GF256Poly { } int size = coefficients.length; int[] product = new int[size + degree]; - System.arraycopy(coefficients, 0, product, 0, size); for (int i = 0; i < size; i++) { - product[i] = field.multiply(product[i], coefficient); + product[i] = field.multiply(coefficients[i], coefficient); } return new GF256Poly(field, product); } diff --git a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java index c53f481a..059007d3 100644 --- a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java @@ -40,14 +40,14 @@ final class DecodedBitStreamParser { ' ', '$', '%', '*', '+', '-', '.', '/', ':' }; private static final String SHIFT_JIS = "Shift_JIS"; + private static final String EUC_JP = "EUC-JP"; private static final boolean ASSUME_SHIFT_JIS; private static final String UTF8 = "UTF-8"; private static final String ISO88591 = "ISO-8859-1"; static { String platformDefault = System.getProperty("file.encoding"); - ASSUME_SHIFT_JIS = SHIFT_JIS.equalsIgnoreCase(platformDefault) || - "EUC-JP".equalsIgnoreCase(platformDefault); + ASSUME_SHIFT_JIS = SHIFT_JIS.equalsIgnoreCase(platformDefault) || EUC_JP.equalsIgnoreCase(platformDefault); } private DecodedBitStreamParser() {