Skip to content

Commit

Permalink
:octocat: some micro optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Oct 16, 2023
1 parent d2dd077 commit af7ba49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Common/ReedSolomonEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ private function encode(array $dataBytes, int $ecByteCount):array{

foreach($ecBytes as $i => &$val){
$modIndex = ($i + $count);
$val = ($modIndex >= 0) ? $modCoefficients[$modIndex] : 0;
$val = 0;

if($modIndex >= 0){
$val = $modCoefficients[$modIndex];
}
}

return $ecBytes;
Expand Down
16 changes: 12 additions & 4 deletions src/Data/QRMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,19 +749,27 @@ public function writeCodewords(BitBuffer $bitBuffer):self{
}

for($count = 0; $count < $this->moduleCount; $count++){
$y = ($direction) ? ($this->moduleCount - 1 - $count) : $count;
$y = $count;

if($direction){
$y = ($this->moduleCount - 1 - $count);
}

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

// skip functional patterns
if($this->get($x, $y) !== $this::M_NULL){
if($this->matrix[$y][$x] !== $this::M_NULL){
continue;
}

$v = $iByte < $byteCount && (($data[$iByte] >> $iBit--) & 1) === 1;
$value = 0;

if($iByte < $byteCount && (($data[$iByte] >> $iBit--) & 1) === 1){
$value = $this::IS_DARK;
}

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

if($iBit === -1){
$iByte++;
Expand Down

0 comments on commit af7ba49

Please sign in to comment.