Просмотр исходного кода

:octocat: a few more performance improvements

smiley 2 лет назад
Родитель
Сommit
5e8d10df82
3 измененных файлов с 11 добавлено и 12 удалено
  1. 2 2
      src/Output/QRGdImage.php
  2. 7 10
      src/Output/QRMarkupSVG.php
  3. 2 0
      src/Output/QROutputAbstract.php

+ 2 - 2
src/Output/QRGdImage.php

@@ -301,8 +301,8 @@ class QRGdImage extends QROutputAbstract{
 				$this->image,
 				(($x * $this->scale) + intdiv($this->scale, 2)),
 				(($y * $this->scale) + intdiv($this->scale, 2)),
-				(int)(2 * $this->circleRadius * $this->scale),
-				(int)(2 * $this->circleRadius * $this->scale),
+				(int)($this->circleDiameter * $this->scale),
+				(int)($this->circleDiameter * $this->scale),
 				$color
 			);
 

+ 7 - 10
src/Output/QRMarkupSVG.php

@@ -180,19 +180,16 @@ class QRMarkupSVG extends QRMarkup{
 		}
 
 		if($this->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->keepAsSquare)){
-			$r = $this->circleRadius;
-
-			return sprintf(
-				'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',
-				($x + 0.5 - $r),
-				($y + 0.5),
-				$r,
-				($r * 2)
-			);
+			// string interpolation: ugly and fast
+			$ix = ($x + 0.5 - $this->circleRadius);
+			$iy = ($y + 0.5);
 
+			// phpcs:ignore
+			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";
 		}
 
-		return sprintf('M%1$s %2$s h1 v1 h-1Z', $x, $y);
+		// phpcs:ignore
+		return "M$x $y h1 v1 h-1Z";
 	}
 
 }

+ 2 - 0
src/Output/QROutputAbstract.php

@@ -63,6 +63,7 @@ abstract class QROutputAbstract implements QROutputInterface{
 	protected array $keepAsSquare;
 	/** @see \chillerlan\QRCode\QROptions::$circleRadius */
 	protected float $circleRadius;
+	protected float $circleDiameter;
 
 	/**
 	 * QROutputAbstract constructor.
@@ -102,6 +103,7 @@ abstract class QROutputAbstract implements QROutputInterface{
 			$this->{$property} = $this->options->{$property};
 		}
 
+		$this->circleDiameter = ($this->circleRadius * 2);
 	}
 
 	/**