Index: select.inc
===================================================================
--- select.inc	(revision 832)
+++ select.inc	(working copy)
@@ -485,38 +485,51 @@
  *   Optional. If specified, return the option array and exclude any optgroups.
  */
 function _webform_select_options($text, $flat = FALSE) {
-  $options = array();
-  $rows = array_filter(explode("\n", trim($text)));
-  $group = NULL;
-  foreach ($rows as $option) {
-    $option = trim($option);
-    /**
-     * If the Key of the option is within < >, treat as an optgroup
-     *
-     * <Group 1>
-     *   creates an optgroup with the label "Group 1"
-     *
-     * <>
-     *   Unsets the current group, allowing items to be inserted at the root element.
-     */
+  static $option_cache = array();
 
-    if (preg_match('/^\<([^>]*)\>$/', $option, $matches)) {
-      if (empty($matches[1])) {
-        unset($group);
+  // Keep each processed option block in an array indexed by the MD5 hash of
+  // the option text and the value of the $flat variable.
+  $md5 = md5($text);
+
+  // Check if this option block has been previously processed.
+  if (!isset($option_cache[$flat][$md5])) {
+
+    $options = array();
+    $rows = array_filter(explode("\n", trim($text)));
+    $group = NULL;
+    foreach ($rows as $option) {
+      $option = trim($option);
+      /**
+       * If the Key of the option is within < >, treat as an optgroup
+       *
+       * <Group 1>
+       *   creates an optgroup with the label "Group 1"
+       *
+       * <>
+       *   Unsets the current group, allowing items to be inserted at the root element.
+       */
+      if (preg_match('/^\<([^>]*)\>$/', $option, $matches)) {
+        if (empty($matches[1])) {
+          unset($group);
+        }
+        elseif (!$flat) {
+          $group = _webform_filter_values($matches[1], NULL, NULL, FALSE);
+        }
       }
-      elseif (!$flat) {
-        $group = _webform_filter_values($matches[1], NULL, NULL, FALSE);
+      elseif (preg_match('/^([^|]+)\|(.*)$/', $option, $matches)) {
+        $key = _webform_filter_values($matches[1], NULL, NULL, FALSE);
+        $value = _webform_filter_values($matches[2], NULL, NULL, FALSE);
+        isset($group) ? $options[$group][$key] = $value : $options[$key] = $value;
       }
+      else {
+        $filtered_option = _webform_filter_values($option, NULL, NULL, FALSE);
+        isset($group) ? $options[$group][$filtered_option] = $filtered_option : $options[$filtered_option] = $filtered_option;
+      }
     }
-    elseif (preg_match('/^([^|]+)\|(.*)$/', $option, $matches)) {
-      $key = _webform_filter_values($matches[1], NULL, NULL, FALSE);
-      $value = _webform_filter_values($matches[2], NULL, NULL, FALSE);
-      isset($group) ? $options[$group][$key] = $value : $options[$key] = $value;
-    }
-    else {
-      $filtered_option = _webform_filter_values($option, NULL, NULL, FALSE);
-      isset($group) ? $options[$group][$filtered_option] = $filtered_option : $options[$filtered_option] = $filtered_option;
-    }
+    
+    $option_cache[$flat][$md5] = $options;
   }
-  return $options;
+
+  // Return our options from the option_cache array.
+  return $option_cache[$flat][$md5];
 }
