Skip to content

Commit 5e8d10d

Browse files
committed
:octocat: a few more performance improvements
1 parent 8049976 commit 5e8d10d

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/Output/QRGdImage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ protected function module(int $x, int $y, int $M_TYPE):void{
301301
$this->image,
302302
(($x * $this->scale) + intdiv($this->scale, 2)),
303303
(($y * $this->scale) + intdiv($this->scale, 2)),
304-
(int)(2 * $this->circleRadius * $this->scale),
305-
(int)(2 * $this->circleRadius * $this->scale),
304+
(int)($this->circleDiameter * $this->scale),
305+
(int)($this->circleDiameter * $this->scale),
306306
$color
307307
);
308308

src/Output/QRMarkupSVG.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,16 @@ protected function module(int $x, int $y, int $M_TYPE):string{
180180
}
181181

182182
if($this->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->keepAsSquare)){
183-
$r = $this->circleRadius;
184-
185-
return sprintf(
186-
'M%1$s %2$s a%3$s %3$s 0 1 0 %4$s 0 a%3$s %3$s 0 1 0 -%4$s 0Z',
187-
($x + 0.5 - $r),
188-
($y + 0.5),
189-
$r,
190-
($r * 2)
191-
);
183+
// string interpolation: ugly and fast
184+
$ix = ($x + 0.5 - $this->circleRadius);
185+
$iy = ($y + 0.5);
192186

187+
// phpcs:ignore
188+
return "M$ix $iy a$this->circleRadius $this->circleRadius 0 1 0 $this->circleDiameter 0 a$this->circleRadius $this->circleRadius 0 1 0 -$this->circleDiameter 0Z";
193189
}
194190

195-
return sprintf('M%1$s %2$s h1 v1 h-1Z', $x, $y);
191+
// phpcs:ignore
192+
return "M$x $y h1 v1 h-1Z";
196193
}
197194

198195
}

src/Output/QROutputAbstract.php

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ abstract class QROutputAbstract implements QROutputInterface{
6363
protected array $keepAsSquare;
6464
/** @see \chillerlan\QRCode\QROptions::$circleRadius */
6565
protected float $circleRadius;
66+
protected float $circleDiameter;
6667

6768
/**
6869
* QROutputAbstract constructor.
@@ -102,6 +103,7 @@ protected function copyVars():void{
102103
$this->{$property} = $this->options->{$property};
103104
}
104105

106+
$this->circleDiameter = ($this->circleRadius * 2);
105107
}
106108

107109
/**

0 commit comments

Comments
 (0)