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 20:25:55 -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,13 @@ 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];
+    $elements['#defaults_loaded'] = TRUE;
   }
 
   // If #markup is not empty and no theme function is set, use theme_markup.
@@ -4981,30 +4984,27 @@ function element_info($type) {
   $cache = &drupal_static(__FUNCTION__);
 
   if (!isset($cache)) {
-    $basic_defaults = element_basic_defaults();
-    $cache = module_invoke_all('element_info');
-    foreach ($cache as $element_type => $info) {
-      $cache[$element_type] = array_merge_recursive($basic_defaults, $info);
+    $basic_defaults = array(
+      '#description' => '',
+      '#title' => '',
+      '#attributes' => array(),
+      '#required' => FALSE,
+      '#attached' => array(),
+    );
+
+    // Add default properties.
+    $cache['defaults'] = $basic_defaults;
+
+    foreach (module_invoke_all('element_info') as $element_type => $info) {
+      $cache[$element_type] = $info + $basic_defaults;
       $cache[$element_type]['#type'] = $element_type;
     }
+
     // Allow modules to alter the element type defaults.
     drupal_alter('element_info', $cache);
   }
 
-  return isset($cache[$type]) ? $cache[$type] : array();
-}
-
-/**
- * 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(),
-  );
+  return isset($cache[$type]) ? $cache[$type] : $cache['defaults'];
 }
 
 /**
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 20:47:37 -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;
@@ -1763,7 +1763,8 @@ function theme_radio($variables) {
   $output .= 'value="' . $element['#return_value'] . '" ';
   $output .= (check_plain($element['#value']) == $element['#return_value']) ? ' checked="checked" ' : ' ';
   $output .= drupal_attributes($element['#attributes']) . ' />';
-  if (!is_null($element['#title'])) {
+
+  if (isset($element['#title'])) {
     $output = '<label class="option" for="' . $element['#id'] . '">' . $output . ' ' . $element['#title'] . '</label>';
   }
 
@@ -2113,7 +2114,7 @@ function theme_checkbox($variables) {
   $checkbox .= $element['#value'] ? ' checked="checked" ' : ' ';
   $checkbox .= drupal_attributes($element['#attributes']) . ' />';
 
-  if (!is_null($element['#title'])) {
+  if (isset($element['#title'])) {
     $checkbox = '<label class="option" for="' . $element['#id'] . '">' . $checkbox . ' ' . $element['#title'] . '</label>';
   }
 
