Tiny optimizations to boolean logic to avoid extra byte code and branches in semi-critical sections

git-svn-id: https://zxing.googlecode.com/svn/trunk@867 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2009-02-23 13:52:45 +00:00
parent b2f3eb6b7b
commit b24fbdd7b0
7 changed files with 12 additions and 12 deletions

View file

@ -231,7 +231,7 @@ public final class Detector {
boolean inBlack = image.isBlack(steep ? fromY : fromX, steep ? fromX : fromY);
for (int x = fromX, y = fromY; x != toX; x += xstep) {
boolean isBlack = image.isBlack(steep ? y : x, steep ? x : y);
if (isBlack == !inBlack) {
if (isBlack != inBlack) {
transitions++;
inBlack = isBlack;
}

View file

@ -169,7 +169,7 @@ public abstract class AbstractOneDReader implements OneDReader {
int i = start;
while (i < end) {
boolean pixel = row.get(i);
if ((!pixel && isWhite) || (pixel && !isWhite)) {
if (pixel ^ isWhite) { // that is, exactly one is true
counters[counterPosition]++;
} else {
counterPosition++;
@ -177,7 +177,7 @@ public abstract class AbstractOneDReader implements OneDReader {
break;
} else {
counters[counterPosition] = 1;
isWhite = !isWhite;
isWhite ^= true; // isWhite = !isWhite; Is this too clever? shorter byte code, no conditional
}
}
i++;

View file

@ -228,7 +228,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
int patternStart = rowOffset;
for (int x = rowOffset; x < width; x++) {
boolean pixel = row.get(x);
if ((!pixel && isWhite) || (pixel && !isWhite)) {
if (pixel ^ isWhite) {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
@ -246,7 +246,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
counterPosition++;
}
counters[counterPosition] = 1;
isWhite = !isWhite;
isWhite ^= true; // isWhite = !isWhite;
}
}
throw ReaderException.getInstance();

View file

@ -180,7 +180,7 @@ public final class Code128Reader extends AbstractOneDReader {
for (int i = rowOffset; i < width; i++) {
boolean pixel = row.get(i);
if ((!pixel && isWhite) || (pixel && !isWhite)) {
if (pixel ^ isWhite) {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
@ -210,7 +210,7 @@ public final class Code128Reader extends AbstractOneDReader {
counterPosition++;
}
counters[counterPosition] = 1;
isWhite = !isWhite;
isWhite ^= true; // isWhite = !isWhite;
}
}
throw ReaderException.getInstance();

View file

@ -184,7 +184,7 @@ public final class Code39Reader extends AbstractOneDReader {
for (int i = rowOffset; i < width; i++) {
boolean pixel = row.get(i);
if ((!pixel && isWhite) || (pixel && !isWhite)) {
if (pixel ^ isWhite) {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
@ -209,7 +209,7 @@ public final class Code39Reader extends AbstractOneDReader {
counterPosition++;
}
counters[counterPosition] = 1;
isWhite = !isWhite;
isWhite ^= true; // isWhite = !isWhite;
}
}
throw ReaderException.getInstance();

View file

@ -296,7 +296,7 @@ public final class ITFReader extends AbstractOneDReader {
int patternStart = rowOffset;
for (int x = rowOffset; x < width; x++) {
boolean pixel = row.get(x);
if ((!pixel && isWhite) || (pixel && !isWhite)) {
if (pixel ^ isWhite) {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
@ -314,7 +314,7 @@ public final class ITFReader extends AbstractOneDReader {
counterPosition++;
}
counters[counterPosition] = 1;
isWhite = !isWhite;
isWhite ^= true; // isWhite = !isWhite;
}
}
throw ReaderException.getInstance();

View file

@ -198,7 +198,7 @@ final class BitMatrixParser {
}
}
}
readingUp = !readingUp; // switch directions
readingUp ^= true; // readingUp = !readingUp; // switch directions
}
if (resultOffset != version.getTotalCodewords()) {
throw ReaderException.getInstance();