From 98741eb09a4a260be4e97cfd6a67272f98047e8a Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Wed, 3 Oct 2018 21:14:02 +0000 Subject: [PATCH] Slightly tweaked logic in Java QrSegmentAdvanced for robustness and efficiency. --- java/io/nayuki/qrcodegen/QrSegmentAdvanced.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java b/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java index c3a9d71..8369a6c 100644 --- a/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java +++ b/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java @@ -62,9 +62,11 @@ public final class QrSegmentAdvanced { // Iterate through version numbers, and make tentative segments List segs = null; + int[] codePoints = toCodePoints(text); for (int version = minVersion; version <= maxVersion; version++) { if (version == minVersion || version == 10 || version == 27) - segs = makeSegmentsOptimally(text, version); + segs = makeSegmentsOptimally(codePoints, version); + assert segs != null; // Check if the segments fit int dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8; @@ -77,10 +79,9 @@ public final class QrSegmentAdvanced { // Returns a list of segments that is optimal for the given text at the given version number. - private static List makeSegmentsOptimally(String text, int version) { - if (text.length() == 0) + private static List makeSegmentsOptimally(int[] codePoints, int version) { + if (codePoints.length == 0) return new ArrayList<>(); - int[] codePoints = toCodePoints(text); Mode[] charModes = computeCharacterModes(codePoints, version); return splitIntoSegments(codePoints, charModes); }