Skip to content

Commit b4780d7

Browse files
committed
:octocat: minor performance improvements for html and string output
1 parent 3ad6b70 commit b4780d7

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

src/Output/QRMarkupHTML.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class QRMarkupHTML extends QRMarkup{
2323
* @inheritDoc
2424
*/
2525
protected function createMarkup(bool $saveToFile):string{
26-
$rows = [];
26+
$rows = [];
27+
$cssClass = $this->getCssClass();
2728

2829
foreach($this->matrix->getMatrix() as $row){
2930
$element = '<span style="background: %s;"></span>';
@@ -32,12 +33,7 @@ protected function createMarkup(bool $saveToFile):string{
3233
$rows[] = sprintf('<div>%s</div>%s', implode('', $modules), $this->eol);
3334
}
3435

35-
$html = sprintf(
36-
'<div class="%1$s">%3$s%2$s</div>%3$s',
37-
$this->getCssClass(),
38-
implode('', $rows),
39-
$this->eol
40-
);
36+
$html = sprintf('<div class="%1$s">%3$s%2$s</div>%3$s', $cssClass, implode('', $rows), $this->eol);
4137

4238
// wrap the snippet into a body when saving to file
4339
if($saveToFile){

src/Output/QRStringText.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace chillerlan\QRCode\Output;
1212

13+
use function array_map;
1314
use function implode;
1415
use function is_string;
1516
use function max;
@@ -51,14 +52,8 @@ public function dump(string $file = null):string{
5152
$lines = [];
5253
$linestart = $this->options->textLineStart;
5354

54-
for($y = 0; $y < $this->moduleCount; $y++){
55-
$r = [];
56-
57-
for($x = 0; $x < $this->moduleCount; $x++){
58-
$r[] = $this->getModuleValueAt($x, $y);
59-
}
60-
61-
$lines[] = $linestart.implode('', $r);
55+
foreach($this->matrix->getMatrix() as $row){
56+
$lines[] = $linestart.implode('', array_map([$this, 'getModuleValue'], $row));
6257
}
6358

6459
$data = implode($this->eol, $lines);

0 commit comments

Comments
 (0)