From aad5bd7d22311bbcf191afa663d9d8086b15731d Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 1 Dec 2023 17:36:28 +0100 Subject: [PATCH] Cache bb code table Signed-off-by: Kamil Tekiela --- src/Sanitize.php | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Sanitize.php b/src/Sanitize.php index d3a58b5bad..f110bf90f0 100644 --- a/src/Sanitize.php +++ b/src/Sanitize.php @@ -174,24 +174,31 @@ class Sanitize $message = strtr($message, ['<' => '<', '>' => '>']); } - /* Interpret bb code */ - $replacePairs = [ - '[em]' => '', - '[/em]' => '', - '[strong]' => '', - '[/strong]' => '', - '[code]' => '', - '[/code]' => '', - '[kbd]' => '', - '[/kbd]' => '', - '[br]' => '
', - '[/a]' => '', - '[/doc]' => '', - '[sup]' => '', - '[/sup]' => '', - // used in libraries/Util.php - '[dochelpicon]' => Html\Generator::getImage('b_help', __('Documentation')), - ]; + /** + * Interpret bb code + * + * @var array $replacePairs + */ + static $replacePairs = []; + if ($replacePairs === []) { + $replacePairs = [ + '[em]' => '', + '[/em]' => '', + '[strong]' => '', + '[/strong]' => '', + '[code]' => '', + '[/code]' => '', + '[kbd]' => '', + '[/kbd]' => '', + '[br]' => '
', + '[/a]' => '', + '[/doc]' => '', + '[sup]' => '', + '[/sup]' => '', + // used in libraries/Util.php + '[dochelpicon]' => Html\Generator::getImage('b_help', __('Documentation')), + ]; + } $message = strtr($message, $replacePairs);