From cf0dbd4d0fc7729f2e37b47a8ebc2a4636852926 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sat, 25 Aug 2018 23:16:49 +0000 Subject: [PATCH] Refactored control flow to reduce nesting. --- .../nayuki/qrcodegen/QrSegmentAdvanced.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java b/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java index 526d1bb..5b2c74a 100644 --- a/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java +++ b/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java @@ -182,23 +182,23 @@ public final class QrSegmentAdvanced { QrSegment.Mode curMode = charModes[0]; int start = 0; for (int i = 1; ; i++) { - if (i >= data.length || charModes[i] != curMode) { - if (curMode == BYTE) - result.add(QrSegment.makeBytes(Arrays.copyOfRange(data, start, i))); - else { - String temp = new String(data, start, i - start, StandardCharsets.US_ASCII); - if (curMode == NUMERIC) - result.add(QrSegment.makeNumeric(temp)); - else if (curMode == ALPHANUMERIC) - result.add(QrSegment.makeAlphanumeric(temp)); - else - throw new AssertionError(); - } - if (i >= data.length) - return result; - curMode = charModes[i]; - start = i; + if (i < data.length && charModes[i] == curMode) + continue; + if (curMode == BYTE) + result.add(QrSegment.makeBytes(Arrays.copyOfRange(data, start, i))); + else { + String temp = new String(data, start, i - start, StandardCharsets.US_ASCII); + if (curMode == NUMERIC) + result.add(QrSegment.makeNumeric(temp)); + else if (curMode == ALPHANUMERIC) + result.add(QrSegment.makeAlphanumeric(temp)); + else + throw new AssertionError(); } + if (i >= data.length) + return result; + curMode = charModes[i]; + start = i; } }