From af7ba49225e73c27657c65dd040708fb95b19acf Mon Sep 17 00:00:00 2001 From: smiley Date: Tue, 17 Oct 2023 00:06:39 +0200 Subject: [PATCH] :octocat: some micro optimization --- src/Common/ReedSolomonEncoder.php | 6 +++++- src/Data/QRMatrix.php | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Common/ReedSolomonEncoder.php b/src/Common/ReedSolomonEncoder.php index 62051796d..4fcdbde45 100644 --- a/src/Common/ReedSolomonEncoder.php +++ b/src/Common/ReedSolomonEncoder.php @@ -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; diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index 5482de5b3..14c428f7e 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -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++;