Skip to content

Commit 75bed90

Browse files
committed
:octocat: let's see how much of a performance difference that makes
1 parent dcf71d6 commit 75bed90

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/Output/QRMarkupSVG.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace chillerlan\QRCode\Output;
1313

14-
use function array_chunk, implode, is_string, preg_match, sprintf, trim;
14+
use chillerlan\QRCode\Data\QRMatrix;
15+
use function array_any, array_chunk, implode, is_string, preg_match, sprintf, trim;
1516

1617
/**
1718
* SVG output
@@ -28,9 +29,13 @@ class QRMarkupSVG extends QRMarkup{
2829

2930
final public const string MIME_TYPE = 'image/svg+xml';
3031

31-
// micro optimization for circle radius and diameter values in long loops
32+
// micro optimization for QROptions values in long loops
3233
protected float $r;
3334
protected float $d;
35+
protected bool $drawLightModules;
36+
protected bool $drawCircularModules;
37+
protected array $keepAsSquare;
38+
3439

3540
/**
3641
* @todo: XSS proof
@@ -68,6 +73,12 @@ protected function getCssClass(int $M_TYPE = 0):string{
6873
}
6974

7075
protected function createMarkup(bool $saveToFile):string{
76+
$this->r = $this->options->circleRadius;
77+
$this->d = ($this->r * 2);
78+
$this->drawCircularModules = $this->options->drawCircularModules;
79+
$this->drawLightModules = $this->options->drawLightModules;
80+
$this->keepAsSquare = $this->options->keepAsSquare;
81+
7182
$svg = $this->header();
7283

7384
if($this->options->svgDefs !== ''){
@@ -120,9 +131,6 @@ protected function header():string{
120131
* returns one or more SVG <path> elements
121132
*/
122133
protected function paths():string{
123-
$this->r = $this->options->circleRadius;
124-
$this->d = ($this->r * 2);
125-
126134
$paths = $this->collectModules();
127135
$svg = [];
128136

@@ -174,11 +182,11 @@ protected function path(string $path, int $M_TYPE):string{
174182
*/
175183
protected function moduleTransform(int $x, int $y, int $M_TYPE, int $M_TYPE_LAYER):string|null{
176184

177-
if(!$this->options->drawLightModules && !$this->matrix->isDark($M_TYPE)){
185+
if(!$this->drawLightModules && !(($M_TYPE & QRMatrix::IS_DARK) === QRMatrix::IS_DARK)){
178186
return null;
179187
}
180188

181-
if($this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)){
189+
if($this->drawCircularModules && !array_any($this->keepAsSquare, fn($type) => ($M_TYPE & $type) === $type)){
182190
// string interpolation: ugly and fast
183191
$ix = ($x + 0.5 - $this->r);
184192
$iy = ($y + 0.5);

src/Output/QRMarkupXML.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace chillerlan\QRCode\Output;
1515

16+
use chillerlan\QRCode\Data\QRMatrix;
1617
use DOMDocument;
1718
use DOMElement;
1819
use function sprintf;
@@ -126,7 +127,7 @@ protected function row(int $y, array $row):DOMElement|null{
126127
* Creates a DOM element for a single module
127128
*/
128129
protected function module(int $x, int $y, int $M_TYPE):DOMElement|null{
129-
$isDark = $this->matrix->isDark($M_TYPE);
130+
$isDark = (($M_TYPE & QRMatrix::IS_DARK) === QRMatrix::IS_DARK);
130131

131132
if(!$this->options->drawLightModules && !$isDark){
132133
return null;

0 commit comments

Comments
 (0)