From 263d9e67eee8ce9ad4a17f8fdf88d2edffef248f Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sun, 27 Jul 2014 23:19:34 +0200 Subject: [PATCH] Reusing instances of MessageFormatter as it is slightly faster --- src/I18n/Formatter/IcuFormatter.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/I18n/Formatter/IcuFormatter.php b/src/I18n/Formatter/IcuFormatter.php index 1338849be98..febbaee37ad 100644 --- a/src/I18n/Formatter/IcuFormatter.php +++ b/src/I18n/Formatter/IcuFormatter.php @@ -72,7 +72,13 @@ public function format($locale, $message, array $vars) { * variables is found */ protected function _formatMessage($locale, $message, $vars) { - $formatter = new MessageFormatter($locale, $message); + if (!isset($this->_formatters[$locale])) { + $this->_formatters[$locale] = new MessageFormatter($locale, $message); + } else { + $this->_formatters[$locale]->setPattern($message); + } + + $formatter = $this->_formatters[$locale]; if (!$formatter) { throw new Exception\CannotInstantiateFormatter(