From 2e66f195cf3baffe767dc8310164b94d2d0224d2 Mon Sep 17 00:00:00 2001
From: Ted Cooper <elc@784944.no-reply.drupal.org>
Date: Tue, 1 Nov 2011 11:49:20 +1000
Subject: [PATCH] Issue #1307890 by ELC: API Fix: Make performance improvement cope with array input.

---
 token.module |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/token.module b/token.module
index a1ae24b..d82471a 100644
--- a/token.module
+++ b/token.module
@@ -251,7 +251,14 @@ function token_replace($text, $type = 'global', $object = NULL, $leading = TOKEN
  */
 function token_replace_multiple($text, $types = array('global' => NULL), $leading = TOKEN_PREFIX, $trailing = TOKEN_SUFFIX, $options = array(), $flush = FALSE) {
   // If there are no tokens to replace, just return the text.
-  $text_tokens = token_scan($text, $leading, $trailing);
+  // Must handle $text being an array.
+  if (is_array($text)) {
+    // replace with a single string to speed up preg_match_all
+    $text_tokens = token_scan(implode(' ', $text), $leading, $trailing);
+  }
+  else {
+    $text_tokens = token_scan($text, $leading, $trailing);
+  }
   if (empty($text_tokens)) {
     return $text;
   }
-- 
1.7.2.5

