Skip to content

Commit af7ba49

Browse files
committed
:octocat: some micro optimization
1 parent d2dd077 commit af7ba49

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/Common/ReedSolomonEncoder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ private function encode(array $dataBytes, int $ecByteCount):array{
100100

101101
foreach($ecBytes as $i => &$val){
102102
$modIndex = ($i + $count);
103-
$val = ($modIndex >= 0) ? $modCoefficients[$modIndex] : 0;
103+
$val = 0;
104+
105+
if($modIndex >= 0){
106+
$val = $modCoefficients[$modIndex];
107+
}
104108
}
105109

106110
return $ecBytes;

src/Data/QRMatrix.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,19 +749,27 @@ public function writeCodewords(BitBuffer $bitBuffer):self{
749749
}
750750

751751
for($count = 0; $count < $this->moduleCount; $count++){
752-
$y = ($direction) ? ($this->moduleCount - 1 - $count) : $count;
752+
$y = $count;
753+
754+
if($direction){
755+
$y = ($this->moduleCount - 1 - $count);
756+
}
753757

754758
for($col = 0; $col < 2; $col++){
755759
$x = ($i - $col);
756760

757761
// skip functional patterns
758-
if($this->get($x, $y) !== $this::M_NULL){
762+
if($this->matrix[$y][$x] !== $this::M_NULL){
759763
continue;
760764
}
761765

762-
$v = $iByte < $byteCount && (($data[$iByte] >> $iBit--) & 1) === 1;
766+
$value = 0;
767+
768+
if($iByte < $byteCount && (($data[$iByte] >> $iBit--) & 1) === 1){
769+
$value = $this::IS_DARK;
770+
}
763771

764-
$this->set($x, $y, $v, $this::M_DATA);
772+
$this->matrix[$y][$x] = ($this::M_DATA | $value);
765773

766774
if($iBit === -1){
767775
$iByte++;

0 commit comments

Comments
 (0)