--- select.inc.orig	2010-03-11 12:27:54.000000000 -0600
+++ select.inc	2010-03-11 12:26:54.000000000 -0600
@@ -552,7 +552,7 @@
     foreach (array_intersect_key($options, $rows) as $key => $label) {
       $ordered_rows[] = $rows[$key];
     }
-  
+
     // Add a row for any unknown or user-entered values.
     if ($component['extra']['other_option'] === 'Y') {
       $full_count = db_result(db_query($count_query, array_merge(array($component['nid'], $component['cid']), $sids)));
@@ -671,40 +671,64 @@
  *   Optional. Whether or not to filter returned values.
  */
 function _webform_select_options($text, $flat = FALSE, $filter = TRUE) {
-  $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 = $filter ? _webform_filter_values($matches[1], NULL, NULL, NULL, FALSE) : $matches[1];
-      }
-    }
-    elseif (preg_match('/^([^|]+)\|(.*)$/', $option, $matches)) {
-      $key = $filter ? _webform_filter_values($matches[1], NULL, NULL, NULL, FALSE) : $matches[1];
-      $value = $filter ? _webform_filter_values($matches[2], NULL, NULL, NULL, FALSE) : $matches[2];
-      isset($group) ? $options[$group][$key] = $value : $options[$key] = $value;
-    }
-    else {
-      $filtered_option = $filter ? _webform_filter_values($option, NULL, NULL, NULL, FALSE) : $option;
-      isset($group) ? $options[$group][$filtered_option] = $filtered_option : $options[$filtered_option] = $filtered_option;
-    }
+  static $all_options;
+  /**
+   * Check if this option block has been previously processed.  We will keep each
+   * processed option block in a global array indexed by the MD5 hash of the option text
+   * for flat selects.  Select lists which are not flat will not be cached.
+   */
+  if (!is_array($all_options)) {
+    $all_options = array();
+  }
+  // Set the value of m based on the value of flat.
+  ($flat) ? $m = md5($text) : $m = NULL;
+  /** This is where we determine if this call should be cached or treated as dynamic
+   * and left uncached (the traditional behavior before caching).
+   */
+  if (!$flat || (!isset($all_options[$m]))) {
+    $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 = $filter ? _webform_filter_values($matches[1], NULL, NULL, NULL, FALSE) : $matches[1];
+        }
+      }
+      elseif (preg_match('/^([^|]+)\|(.*)$/', $option, $matches)) {
+        $key = $filter ? _webform_filter_values($matches[1], NULL, NULL, NULL, FALSE) : $matches[1];
+        $value = $filter ? _webform_filter_values($matches[2], NULL, NULL, NULL, FALSE) : $matches[2];
+        isset($group) ? $options[$group][$key] = $value : $options[$key] = $value;
+      }
+      else {
+        $filtered_option = $filter ? _webform_filter_values($option, NULL, NULL, NULL, FALSE) : $option;
+        isset($group) ? $options[$group][$filtered_option] = $filtered_option : $options[$filtered_option] = $filtered_option;
+      }
+      if ($flat) { $all_options[$m] = $options; }
+    }
+  }
+  /** Time to check the cache.  If our all_options array contains a match we should return it
+   * otherwise we return the standard generated options
+   */
+  if ($flat && isset($all_options[$m])) {
+    return $all_options[$m];
+  }
+  else {
+    return $options;
   }
-  return $options;
 }
 
 /**
