From b0ac4796a69d1640b0e6150cc2b02a6ae7e59cff Mon Sep 17 00:00:00 2001 From: Dries Date: Tue, 24 Jan 2012 20:18:44 -0500 Subject: - Patch #1346166 by Dave Reid: Improve performance of token_replace() if there are no tokens to replace. --- includes/token.inc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'includes') diff --git a/includes/token.inc b/includes/token.inc index edc8a962f..0b05c68f4 100644 --- a/includes/token.inc +++ b/includes/token.inc @@ -77,8 +77,13 @@ * Text with tokens replaced. */ function token_replace($text, array $data = array(), array $options = array()) { + $text_tokens = token_scan($text); + if (empty($text_tokens)) { + return $text; + } + $replacements = array(); - foreach (token_scan($text) as $type => $tokens) { + foreach ($text_tokens as $type => $tokens) { $replacements += token_generate($type, $tokens, $data, $options); if (!empty($options['clear'])) { $replacements += array_fill_keys($tokens, ''); -- cgit v1.2.3