Skip to content

Commit 10e1162

Browse files
committed
🚿 simplified
1 parent a7e9642 commit 10e1162

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Common/ReedSolomonDecoder.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace chillerlan\QRCode\Common;
1313

1414
use RuntimeException;
15-
use function array_fill, count;
15+
use function array_fill, array_reverse, count;
1616

1717
/**
1818
* Implements Reed-Solomon decoding, as the name implies.
@@ -48,24 +48,23 @@ final class ReedSolomonDecoder{
4848
public function decode(array $received, int $numEccCodewords):array{
4949
$poly = new GenericGFPoly($received);
5050
$syndromeCoefficients = [];
51-
$noError = true;
51+
$error = false;
5252

53-
for($i = 0, $j = $numEccCodewords - 1; $i < $numEccCodewords; $i++, $j--){
54-
$eval = $poly->evaluateAt(GF256::exp($i));
55-
$syndromeCoefficients[$j] = $eval;
53+
for($i = 0; $i < $numEccCodewords; $i++){
54+
$syndromeCoefficients[$i] = $poly->evaluateAt(GF256::exp($i));
5655

57-
if($eval !== 0){
58-
$noError = false;
56+
if($syndromeCoefficients[$i] !== 0){
57+
$error = true;
5958
}
6059
}
6160

62-
if($noError){
61+
if(!$error){
6362
return $received;
6463
}
6564

6665
[$sigma, $omega] = $this->runEuclideanAlgorithm(
6766
GF256::buildMonomial($numEccCodewords, 1),
68-
new GenericGFPoly($syndromeCoefficients),
67+
new GenericGFPoly(array_reverse($syndromeCoefficients)),
6968
$numEccCodewords
7069
);
7170

0 commit comments

Comments
 (0)