Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1032
diff -u -p -r1.1032 common.inc
--- includes/common.inc	31 Oct 2009 16:06:35 -0000	1.1032
+++ includes/common.inc	31 Oct 2009 18:35:56 -0000
@@ -4669,7 +4669,11 @@ function drupal_render_page($page) {
  *   The rendered HTML.
  */
 function drupal_render(&$elements) {
-  static $defaults;
+  // Element #type information should not change within a single request, and
+  // drupal_render() is called a lot, so we statically cache the #type
+  // information of already requested types to save many function calls.
+  static $element_info;
+
   // Early-return nothing if user does not have access.
   if (!isset($elements) || (isset($elements['#access']) && !$elements['#access'])) {
     return;
@@ -4687,14 +4691,12 @@ function drupal_render(&$elements) {
 
   // If the default values for this element have not been loaded yet, populate
   // them.
-  if (isset($elements['#type']) && empty($elements['#defaults_loaded'])) {
-    $elements += element_info($elements['#type']);
-  }
-  else {
-    if (!isset($defaults)) {
-      $defaults = element_basic_defaults();
+  if (empty($elements['#defaults_loaded'])) {
+    $type = isset($elements['#type']) ? $elements['#type'] : 'defaults';
+    if (!isset($element_info[$type])) {
+      $element_info[$type] = element_info($type);
     }
-    $elements += $defaults;
+    $elements += $element_info[$type];
   }
 
   // If #markup is not empty and no theme function is set, use theme_markup.
@@ -4981,12 +4983,24 @@ function element_info($type) {
   $cache = &drupal_static(__FUNCTION__);
 
   if (!isset($cache)) {
-    $basic_defaults = element_basic_defaults();
+    $basic_defaults = array(
+      '#description' => '',
+      '#title' => '',
+      '#attributes' => array(),
+      '#required' => FALSE,
+      '#attached' => array(),
+    );
+
+    // Load all the elements, keyed by their #type.
     $cache = module_invoke_all('element_info');
     foreach ($cache as $element_type => $info) {
-      $cache[$element_type] = array_merge_recursive($basic_defaults, $info);
+      $cache[$element_type] = $info + $basic_defaults;
       $cache[$element_type]['#type'] = $element_type;
     }
+
+    // Add default properties.
+    $cache['defaults'] = $basic_defaults;
+
     // Allow modules to alter the element type defaults.
     drupal_alter('element_info', $cache);
   }
@@ -4995,19 +5009,6 @@ function element_info($type) {
 }
 
 /**
- * Retrieve the basic default properties that are common to all elements.
- */
-function element_basic_defaults() {
-  return array(
-    '#description' => '',
-    '#title' => '',
-    '#attributes' => array(),
-    '#required' => FALSE,
-    '#attached' => array(),
-  );
-}
-
-/**
  * Function used by uasort to sort structured arrays by weight, without the property weight prefix.
  */
 function drupal_sort_weight($a, $b) {
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.387
diff -u -p -r1.387 form.inc
--- includes/form.inc	27 Oct 2009 04:12:39 -0000	1.387
+++ includes/form.inc	31 Oct 2009 18:33:46 -0000
@@ -1008,7 +1008,7 @@ function form_builder($form_id, $element
   $element['#processed'] = FALSE;
 
   // Use element defaults.
-  if ((!empty($element['#type'])) && ($info = element_info($element['#type']))) {
+  if (isset($element['#type']) && ($info = element_info($element['#type']))) {
     // Overlay $info onto $element, retaining preexisting keys in $element.
     $element += $info;
     $element['#defaults_loaded'] = TRUE;
