Skip to content

Commit 401f2d8

Browse files
committed
Faster Exporter-> exportString()
1 parent 7eb922f commit 401f2d8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/Exporter.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use function sprintf;
3131
use function str_repeat;
3232
use function str_replace;
33+
use function strtr;
3334
use function var_export;
3435
use BackedEnum;
3536
use ReflectionObject;
@@ -318,14 +319,14 @@ private function exportString(string $value): string
318319
}
319320

320321
return "'" .
321-
str_replace(
322-
'<lf>',
323-
"\n",
324-
str_replace(
325-
["\r\n", "\n\r", "\r", "\n"],
326-
['\r\n<lf>', '\n\r<lf>', '\r<lf>', '\n<lf>'],
327-
$value,
328-
),
322+
strtr(
323+
$value,
324+
[
325+
"\r\n" => '\r\n' . "\n",
326+
"\n\r" => '\n\r' . "\n",
327+
"\r" => '\r' . "\n",
328+
"\n" => '\n' . "\n",
329+
],
329330
) .
330331
"'";
331332
}

0 commit comments

Comments
 (0)