From 764f1177efe7bafe5ab47b21968d4b0921c3896c Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Wed, 14 Dec 2005 20:10:45 +0000
Subject: [PATCH] - Patch #40631 by Chris Johnson: is_array() slower than
 isset() or empty().

---
 includes/common.inc              |  2 +-
 includes/database.inc            |  2 +-
 includes/file.inc                |  2 +-
 includes/form.inc                | 11 ++++++-----
 includes/image.inc               |  2 +-
 includes/module.inc              |  2 +-
 modules/block.module             |  3 ++-
 modules/block/block.module       |  3 ++-
 modules/comment.module           |  4 ++--
 modules/comment/comment.module   |  4 ++--
 modules/filter.module            |  6 +++---
 modules/filter/filter.module     |  6 +++---
 modules/node.module              |  8 ++++----
 modules/node/node.module         |  8 ++++----
 modules/search.module            |  4 ++--
 modules/search/search.module     |  4 ++--
 modules/taxonomy.module          |  2 +-
 modules/taxonomy/taxonomy.module |  2 +-
 themes/bluemarine/page.tpl.php   |  4 ++--
 themes/chameleon/chameleon.theme |  6 +++---
 themes/pushbutton/page.tpl.php   |  4 ++--
 21 files changed, 46 insertions(+), 43 deletions(-)

diff --git a/includes/common.inc b/includes/common.inc
index 7c676e5e03ff..3c56472df962 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -741,7 +741,7 @@ function format_rss_item($title, $link, $description, $args = array()) {
     if (is_array($value)) {
       if ($value['key']) {
         $output .= ' <'. $value['key'];
-        if (is_array($value['attributes'])) {
+        if (isset($value['attributes']) && is_array($value['attributes'])) {
           $output .= drupal_attributes($value['attributes']);
         }
 
diff --git a/includes/database.inc b/includes/database.inc
index 744284ece93d..2c3fe975b87b 100644
--- a/includes/database.inc
+++ b/includes/database.inc
@@ -232,7 +232,7 @@ function _db_rewrite_sql($query = '', $primary_table = 'n', $primary_field = 'ni
   $distinct = FALSE;
   foreach (module_implements('db_rewrite_sql') as $module) {
     $result = module_invoke($module, 'db_rewrite_sql', $query, $primary_table, $primary_field, $args);
-    if (is_array($result)) {
+    if (isset($result) && is_array($result)) {
       if (isset($result['where'])) {
         $where[] .= $result['where'];
       }
diff --git a/includes/file.inc b/includes/file.inc
index 95a08cb29026..dbd981bb2ec7 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -490,7 +490,7 @@ function file_download() {
       if ($headers === -1) {
         drupal_access_denied();
       }
-      elseif (is_array($headers)) {
+      elseif (isset($headers) && is_array($headers)) {
         file_transfer($file, $headers);
       }
     }
diff --git a/includes/form.inc b/includes/form.inc
index fd1dc8482ee5..3af3d1375e37 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -318,10 +318,11 @@ function _form_builder($form_id, $form) {
  *   The rendered HTML form.
  */
 function form_render(&$elements) {
-  $content = '';
-  if (is_array($elements)) {
-    uasort($elements, "_form_sort");
+  if (!isset($elements)) {
+    return NULL;
   }
+  $content = '';
+  uasort($elements, "_form_sort");
 
   if (!$elements['#children']) {
     /* render all the children using a theme function */
@@ -380,11 +381,11 @@ function _element_info($type, $refresh = null) {
     '#tree' => FALSE,
     '#parents' => $parents
   );
-  if ($refresh || !is_array($cache)) {
+  if ($refresh || !isset($cache)) {
     $cache = array();
     foreach (module_implements('elements') as $module) {
       $elements = module_invoke($module, 'elements');
-      if (is_array($elements)) {
+      if (isset($elements) && is_array($elements)) {
         $cache = array_merge_recursive($cache, $elements);
       }
     }
diff --git a/includes/image.inc b/includes/image.inc
index a4cf79b4460b..cea0be011e3d 100644
--- a/includes/image.inc
+++ b/includes/image.inc
@@ -89,7 +89,7 @@ function image_get_info($file) {
   $data = @getimagesize($file);
   $file_size = @filesize($file);
 
-  if (is_array($data)) {
+  if (isset($data) && is_array($data)) {
     $extensions = array('1' => 'gif', '2' => 'jpg', '3' => 'png');
     $extension = array_key_exists($data[2], $extensions) ?  $extensions[$data[2]] : '';
     $details = array('width'     => $data[0],
diff --git a/includes/module.inc b/includes/module.inc
index 748333a35a49..f4f5907725d7 100644
--- a/includes/module.inc
+++ b/includes/module.inc
@@ -190,7 +190,7 @@ function module_invoke_all() {
   foreach (module_implements($hook) as $module) {
     $function = $module .'_'. $hook;
     $result = call_user_func_array($function, $args);
-    if (is_array($result)) {
+    if (isset($result) && is_array($result)) {
       $return = array_merge($return, $result);
     }
     else if (isset($result)) {
diff --git a/modules/block.module b/modules/block.module
index d15f3ed4c279..ad479f239d28 100644
--- a/modules/block.module
+++ b/modules/block.module
@@ -599,7 +599,8 @@ function block_list($region) {
         // Check the current throttle status and see if block should be displayed
         // based on server load.
         if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) {
-          if (is_array($array = module_invoke($block->module, 'block', 'view', $block->delta))) {
+          $array = module_invoke($block->module, 'block', 'view', $block->delta);
+          if (isset($array) && is_array($array)) {
             foreach ($array as $k => $v) {
               $block->$k = $v;
             }
diff --git a/modules/block/block.module b/modules/block/block.module
index d15f3ed4c279..ad479f239d28 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -599,7 +599,8 @@ function block_list($region) {
         // Check the current throttle status and see if block should be displayed
         // based on server load.
         if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) {
-          if (is_array($array = module_invoke($block->module, 'block', 'view', $block->delta))) {
+          $array = module_invoke($block->module, 'block', 'view', $block->delta);
+          if (isset($array) && is_array($array)) {
             foreach ($array as $k => $v) {
               $block->$k = $v;
             }
diff --git a/modules/comment.module b/modules/comment.module
index efca38ca5025..c4dac7d36dfb 100644
--- a/modules/comment.module
+++ b/modules/comment.module
@@ -1112,7 +1112,7 @@ function theme_comment_admin_overview($form) {
   $header = array(NULL, t('Subject'), t('Author'), t('Time'), t('Operations'));
 
   $output = form_render($form['options']);
-  if (is_array($form['subject'])) {
+  if (isset($form['subject']) && is_array($form['subject'])) {
     foreach (element_children($form['subject']) as $key) {
       $row = array();
       $row[] = form_render($form['comments'][$key]);
@@ -1657,7 +1657,7 @@ function comment_invoke_comment(&$comment, $op) {
   foreach (module_implements('comment') as $name) {
     $function = $name .'_comment';
     $result = $function($comment, $op);
-    if (is_array($result)) {
+    if (isset($result) && is_array($result)) {
       $return = array_merge($return, $result);
     }
     else if (isset($result)) {
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index efca38ca5025..c4dac7d36dfb 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -1112,7 +1112,7 @@ function theme_comment_admin_overview($form) {
   $header = array(NULL, t('Subject'), t('Author'), t('Time'), t('Operations'));
 
   $output = form_render($form['options']);
-  if (is_array($form['subject'])) {
+  if (isset($form['subject']) && is_array($form['subject'])) {
     foreach (element_children($form['subject']) as $key) {
       $row = array();
       $row[] = form_render($form['comments'][$key]);
@@ -1657,7 +1657,7 @@ function comment_invoke_comment(&$comment, $op) {
   foreach (module_implements('comment') as $name) {
     $function = $name .'_comment';
     $result = $function($comment, $op);
-    if (is_array($result)) {
+    if (isset($result) && is_array($result)) {
       $return = array_merge($return, $result);
     }
     else if (isset($result)) {
diff --git a/modules/filter.module b/modules/filter.module
index 173c0b253100..30fcbae966cc 100644
--- a/modules/filter.module
+++ b/modules/filter.module
@@ -556,7 +556,7 @@ function filter_admin_configure() {
   $form = array();
   foreach ($list as $filter) {
     $form_module = module_invoke($filter->module, 'filter', 'settings', $filter->delta, $format);
-    if (is_array($form_module)) {
+    if (isset($form_module) && is_array($form_module)) {
       $form = array_merge($form, $form_module);
     }
   }
@@ -613,7 +613,7 @@ function filter_list_all() {
 
   foreach (module_list() as $module) {
     $list = module_invoke($module, 'filter', 'list');
-    if (is_array($list)) {
+    if (isset($list) && is_array($list)) {
       foreach ($list as $delta => $name) {
         $filters[$module .'/'. $delta] = (object)array('module' => $module, 'delta' => $delta, 'name' => $name);
       }
@@ -655,7 +655,7 @@ function filter_list_format($format) {
     $result = db_query("SELECT * FROM {filters} WHERE format = %d ORDER BY weight ASC", $format);
     while ($filter = db_fetch_object($result)) {
       $list = module_invoke($filter->module, 'filter', 'list');
-      if (is_array($list) && isset($list[$filter->delta])) {
+      if (isset($list) && is_array($list) && isset($list[$filter->delta])) {
         $filter->name = $list[$filter->delta];
         $filters[$format][$filter->module .'/'. $filter->delta] = $filter;
       }
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index 173c0b253100..30fcbae966cc 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -556,7 +556,7 @@ function filter_admin_configure() {
   $form = array();
   foreach ($list as $filter) {
     $form_module = module_invoke($filter->module, 'filter', 'settings', $filter->delta, $format);
-    if (is_array($form_module)) {
+    if (isset($form_module) && is_array($form_module)) {
       $form = array_merge($form, $form_module);
     }
   }
@@ -613,7 +613,7 @@ function filter_list_all() {
 
   foreach (module_list() as $module) {
     $list = module_invoke($module, 'filter', 'list');
-    if (is_array($list)) {
+    if (isset($list) && is_array($list)) {
       foreach ($list as $delta => $name) {
         $filters[$module .'/'. $delta] = (object)array('module' => $module, 'delta' => $delta, 'name' => $name);
       }
@@ -655,7 +655,7 @@ function filter_list_format($format) {
     $result = db_query("SELECT * FROM {filters} WHERE format = %d ORDER BY weight ASC", $format);
     while ($filter = db_fetch_object($result)) {
       $list = module_invoke($filter->module, 'filter', 'list');
-      if (is_array($list) && isset($list[$filter->delta])) {
+      if (isset($list) && is_array($list) && isset($list[$filter->delta])) {
         $filter->name = $list[$filter->delta];
         $filters[$format][$filter->module .'/'. $filter->delta] = $filter;
       }
diff --git a/modules/node.module b/modules/node.module
index 32a4d98c7644..0a7d3b75f60b 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -315,7 +315,7 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   foreach (module_implements('nodeapi') as $name) {
     $function = $name .'_nodeapi';
     $result = $function($node, $op, $a3, $a4);
-    if (is_array($result)) {
+    if (isset($result) && is_array($result)) {
       $return = array_merge($return, $result);
     }
     else if (isset($result)) {
@@ -751,10 +751,10 @@ function node_search($op = 'search', $keys = null) {
     case 'post':
       // Insert extra restrictions into the search keywords string.
       $edit = &$_POST['edit'];
-      if (is_array($edit['type'])) {
+      if (isset($edit['type']) && is_array($edit['type'])) {
         $keys = search_query_insert($keys, 'type', implode(',', array_keys($edit['type'])));
       }
-      if (is_array($edit['category'])) {
+      if (isset($edit['category']) && is_array($edit['category'])) {
         $keys = search_query_insert($keys, 'category', implode(',', $edit['category']));
       }
       if ($edit['or'] != '') {
@@ -1172,7 +1172,7 @@ function theme_node_admin_nodes($form) {
   $header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), t('Operations'));
 
   $output .= form_render($form['options']);
-  if (is_array($form['title'])) {
+  if (isset($form['title']) && is_array($form['title'])) {
     foreach (element_children($form['title']) as $key) {
       $row = array();
       $row[] = form_render($form['nodes'][$key]);
diff --git a/modules/node/node.module b/modules/node/node.module
index 32a4d98c7644..0a7d3b75f60b 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -315,7 +315,7 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   foreach (module_implements('nodeapi') as $name) {
     $function = $name .'_nodeapi';
     $result = $function($node, $op, $a3, $a4);
-    if (is_array($result)) {
+    if (isset($result) && is_array($result)) {
       $return = array_merge($return, $result);
     }
     else if (isset($result)) {
@@ -751,10 +751,10 @@ function node_search($op = 'search', $keys = null) {
     case 'post':
       // Insert extra restrictions into the search keywords string.
       $edit = &$_POST['edit'];
-      if (is_array($edit['type'])) {
+      if (isset($edit['type']) && is_array($edit['type'])) {
         $keys = search_query_insert($keys, 'type', implode(',', array_keys($edit['type'])));
       }
-      if (is_array($edit['category'])) {
+      if (isset($edit['category']) && is_array($edit['category'])) {
         $keys = search_query_insert($keys, 'category', implode(',', $edit['category']));
       }
       if ($edit['or'] != '') {
@@ -1172,7 +1172,7 @@ function theme_node_admin_nodes($form) {
   $header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), t('Operations'));
 
   $output .= form_render($form['options']);
-  if (is_array($form['title'])) {
+  if (isset($form['title']) && is_array($form['title'])) {
     foreach (element_children($form['title']) as $key) {
       $row = array();
       $row[] = form_render($form['nodes'][$key]);
diff --git a/modules/search.module b/modules/search.module
index 908509da962e..2755b19eb96e 100644
--- a/modules/search.module
+++ b/modules/search.module
@@ -975,7 +975,7 @@ function search_form($action = '', $keys = '', $type = null, $prompt = null) {
   $form['basic']['inline']['submit'] = array('#type' => 'submit', '#value' => t('Search'));
 
   $form_module = module_invoke($type, 'search', 'form', $keys);
-  if (is_array($form_module)) {
+  if (isset($form_module) && is_array($form_module)) {
     $form = array_merge($form, $form_module);
   }
 
@@ -991,7 +991,7 @@ function search_data($keys = NULL, $type = 'node') {
   if (isset($keys)) {
     if (module_hook($type, 'search')) {
       $results = module_invoke($type, 'search', 'search', $keys);
-      if (is_array($results) && count($results)) {
+      if (isset($results) && is_array($results) && count($results)) {
         $output .= '<dl class="search-results">';
         foreach ($results as $entry) {
           $output .= theme('search_item', $entry, $type);
diff --git a/modules/search/search.module b/modules/search/search.module
index 908509da962e..2755b19eb96e 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -975,7 +975,7 @@ function search_form($action = '', $keys = '', $type = null, $prompt = null) {
   $form['basic']['inline']['submit'] = array('#type' => 'submit', '#value' => t('Search'));
 
   $form_module = module_invoke($type, 'search', 'form', $keys);
-  if (is_array($form_module)) {
+  if (isset($form_module) && is_array($form_module)) {
     $form = array_merge($form, $form_module);
   }
 
@@ -991,7 +991,7 @@ function search_data($keys = NULL, $type = 'node') {
   if (isset($keys)) {
     if (module_hook($type, 'search')) {
       $results = module_invoke($type, 'search', 'search', $keys);
-      if (is_array($results) && count($results)) {
+      if (isset($results) && is_array($results) && count($results)) {
         $output .= '<dl class="search-results">';
         foreach ($results as $entry) {
           $output .= theme('search_item', $entry, $type);
diff --git a/modules/taxonomy.module b/modules/taxonomy.module
index 5b4bd3627d76..eda75a7b10ad 100644
--- a/modules/taxonomy.module
+++ b/modules/taxonomy.module
@@ -596,7 +596,7 @@ function taxonomy_node_save($nid, $terms) {
 
   // Free tagging vocabularies do not send their tids in the form,
   // so we'll detect them here and process them independently.
-  if ($terms['tags']) {
+  if (isset($terms['tags'])) {
     $typed_input = $terms['tags'];
     unset($terms['tags']);
 
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 5b4bd3627d76..eda75a7b10ad 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -596,7 +596,7 @@ function taxonomy_node_save($nid, $terms) {
 
   // Free tagging vocabularies do not send their tids in the form,
   // so we'll detect them here and process them independently.
-  if ($terms['tags']) {
+  if (isset($terms['tags'])) {
     $typed_input = $terms['tags'];
     unset($terms['tags']);
 
diff --git a/themes/bluemarine/page.tpl.php b/themes/bluemarine/page.tpl.php
index 3039ce7fb165..9683955bf263 100644
--- a/themes/bluemarine/page.tpl.php
+++ b/themes/bluemarine/page.tpl.php
@@ -18,8 +18,8 @@
       <?php if ($site_slogan) { ?><div class='site-slogan'><?php print $site_slogan ?></div><?php } ?>
     </td>
     <td id="menu">
-      <?php if ($secondary_links) { ?><div id="secondary"><?php print theme('links', $secondary_links) ?></div><?php } ?>
-      <?php if ($primary_links) { ?><div id="primary"><?php print theme('links', $primary_links) ?></div><?php } ?>
+      <?php if (isset($secondary_links)) { ?><div id="secondary"><?php print theme('links', $secondary_links) ?></div><?php } ?>
+      <?php if (isset($primary_links)) { ?><div id="primary"><?php print theme('links', $primary_links) ?></div><?php } ?>
       <?php print $search_box ?>
     </td>
   </tr>
diff --git a/themes/chameleon/chameleon.theme b/themes/chameleon/chameleon.theme
index 0eb915658e04..54def5f6e512 100644
--- a/themes/chameleon/chameleon.theme
+++ b/themes/chameleon/chameleon.theme
@@ -55,12 +55,12 @@ function chameleon_page($content) {
 
   $primary_links = theme('links', menu_primary_links());
   $secondary_links = theme('links', menu_secondary_links());
-  if ($primary_links || $secondary_links) {
+  if (isset($primary_links) || isset($secondary_links)) {
     $output .= ' <div class="navlinks">';
-    if ($primary_links) {
+    if (isset($primary_links)) {
       $output .= '<div class="primary">'. $primary_links .'</div>';
     }
-    if ($secondary_links) {
+    if (($secondary_links)) {
       $output .= '<div class="secondary">'. $secondary_links .'</div>';
     }
     $output .= " </div>\n";
diff --git a/themes/pushbutton/page.tpl.php b/themes/pushbutton/page.tpl.php
index e64e8569c9d5..c986023cac8f 100644
--- a/themes/pushbutton/page.tpl.php
+++ b/themes/pushbutton/page.tpl.php
@@ -102,12 +102,12 @@
 <table id="footer-menu" summary="Navigation elements." border="0" cellpadding="0" cellspacing="0" width="100%">
   <tr>
     <td align="center" valign="middle">
-    <?php if (is_array($primary_links)) : ?>
+    <?php if (isset($primary_links)) : ?>
       <div class="primary-links">
         <?php print theme('links', $primary_links) ?>
       </div>
     <?php endif; ?>
-    <?php if (is_array($secondary_links)) : ?>
+    <?php if (isset($secondary_links)) : ?>
       <div class="secondary-links">
         <?php print theme('links', $secondary_links) ?>
       </div>
-- 
GitLab