Remove obsolete unrolled loops

This commit is contained in:
Sean Owen 2017-11-20 14:12:13 -06:00
parent 3ae6b336e1
commit a3018f8768
4 changed files with 28 additions and 56 deletions

View file

@ -248,11 +248,7 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
int[] stateCount = new int[5]; int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI; i += iSkip) { for (int i = iSkip - 1; i < maxI; i += iSkip) {
// Get a row of black/white values // Get a row of black/white values
stateCount[0] = 0; clearCounts(stateCount);
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
int currentState = 0; int currentState = 0;
for (int j = 0; j < maxJ; j++) { for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) { if (image.get(j, i)) {
@ -267,17 +263,9 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j)) { // Yes if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j)) { // Yes
// Clear state to start looking again // Clear state to start looking again
currentState = 0; currentState = 0;
stateCount[0] = 0; clearCounts(stateCount);
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
} else { // No, shift counts back by two } else { // No, shift counts back by two
stateCount[0] = stateCount[2]; shiftCounts2(stateCount);
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];
stateCount[3] = 1;
stateCount[4] = 0;
currentState = 3; currentState = 3;
} }
} else { } else {

View file

@ -186,14 +186,9 @@ public final class RSS14Reader extends AbstractRSSReader {
throws NotFoundException { throws NotFoundException {
int[] counters = getDataCharacterCounters(); int[] counters = getDataCharacterCounters();
counters[0] = 0; for (int x = 0; x < counters.length; x++) {
counters[1] = 0; counters[x] = 0;
counters[2] = 0; }
counters[3] = 0;
counters[4] = 0;
counters[5] = 0;
counters[6] = 0;
counters[7] = 0;
if (outsideChar) { if (outsideChar) {
recordPatternInReverse(row, pattern.getStartEnd()[0], counters); recordPatternInReverse(row, pattern.getStartEnd()[0], counters);

View file

@ -582,14 +582,9 @@ public final class RSSExpandedReader extends AbstractRSSReader {
boolean isOddPattern, boolean isOddPattern,
boolean leftChar) throws NotFoundException { boolean leftChar) throws NotFoundException {
int[] counters = this.getDataCharacterCounters(); int[] counters = this.getDataCharacterCounters();
counters[0] = 0; for (int x = 0; x < counters.length; x++) {
counters[1] = 0; counters[x] = 0;
counters[2] = 0; }
counters[3] = 0;
counters[4] = 0;
counters[5] = 0;
counters[6] = 0;
counters[7] = 0;
if (leftChar) { if (leftChar) {
recordPatternInReverse(row, pattern.getStartEnd()[0], counters); recordPatternInReverse(row, pattern.getStartEnd()[0], counters);

View file

@ -93,11 +93,7 @@ public class FinderPatternFinder {
int[] stateCount = new int[5]; int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI && !done; i += iSkip) { for (int i = iSkip - 1; i < maxI && !done; i += iSkip) {
// Get a row of black/white values // Get a row of black/white values
stateCount[0] = 0; clearCounts(stateCount);
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
int currentState = 0; int currentState = 0;
for (int j = 0; j < maxJ; j++) { for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) { if (image.get(j, i)) {
@ -133,27 +129,15 @@ public class FinderPatternFinder {
} }
} }
} else { } else {
stateCount[0] = stateCount[2]; shiftCounts2(stateCount);
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];
stateCount[3] = 1;
stateCount[4] = 0;
currentState = 3; currentState = 3;
continue; continue;
} }
// Clear state to start looking again // Clear state to start looking again
currentState = 0; currentState = 0;
stateCount[0] = 0; clearCounts(stateCount);
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
} else { // No, shift counts back by two } else { // No, shift counts back by two
stateCount[0] = stateCount[2]; shiftCounts2(stateCount);
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];
stateCount[3] = 1;
stateCount[4] = 0;
currentState = 3; currentState = 3;
} }
} else { } else {
@ -247,14 +231,24 @@ public class FinderPatternFinder {
} }
private int[] getCrossCheckStateCount() { private int[] getCrossCheckStateCount() {
crossCheckStateCount[0] = 0; clearCounts(crossCheckStateCount);
crossCheckStateCount[1] = 0;
crossCheckStateCount[2] = 0;
crossCheckStateCount[3] = 0;
crossCheckStateCount[4] = 0;
return crossCheckStateCount; return crossCheckStateCount;
} }
protected final void clearCounts(int[] counts) {
for (int x = 0; x < counts.length; x++) {
counts[x] = 0;
}
}
protected final void shiftCounts2(int[] stateCount) {
stateCount[0] = stateCount[2];
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];
stateCount[3] = 1;
stateCount[4] = 0;
}
/** /**
* After a vertical and horizontal scan finds a potential finder pattern, this method * After a vertical and horizontal scan finds a potential finder pattern, this method
* "cross-cross-cross-checks" by scanning down diagonally through the center of the possible * "cross-cross-cross-checks" by scanning down diagonally through the center of the possible