From ea2d79109595f0c936259ffacfccd904f8dcd599 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Sat, 31 Dec 2005 10:48:56 +0000 Subject: [PATCH] - Patch 41169 by Chris: got rid of expensvie object 2 array casts. --- includes/common.inc | 44 ------------------- misc/drupal.js | 2 +- misc/textarea.js | 6 +-- modules/blogapi.module | 4 +- modules/blogapi/blogapi.module | 4 +- modules/comment.module | 4 +- modules/comment/comment.module | 4 +- modules/forum.module | 4 +- modules/forum/forum.module | 4 +- modules/node.module | 12 ++--- modules/node/node.module | 12 ++--- modules/taxonomy.module | 4 +- modules/taxonomy/taxonomy.module | 4 +- modules/upload.module | 2 +- modules/upload/upload.module | 2 +- modules/user.module | 4 +- modules/user/user.module | 4 +- themes/engines/phptemplate/phptemplate.engine | 2 +- 18 files changed, 39 insertions(+), 83 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index 6fc5436330f4..210403561f51 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -489,50 +489,6 @@ function fix_gpc_magic() { } } -/** - * @name Conversion - * @{ - * Converts data structures to different types. - */ - -/** - * Convert an associative array to an anonymous object. - */ -function array2object($array) { - if (is_array($array)) { - $object = new StdClass(); - foreach ($array as $key => $value) { - $object->$key = $value; - } - } - else { - $object = $array; - } - - return $object; -} - -/** - * Convert an object to an associative array. - */ -function object2array($object) { - if (is_object($object)) { - foreach ($object as $key => $value) { - $array[$key] = $value; - } - } - else { - $array = $object; - } - - return $array; -} - - -/** - * @} End of "Conversion". - */ - /** * @name Messages * @{ diff --git a/misc/drupal.js b/misc/drupal.js index c19dc565a45d..7f3a44cea990 100644 --- a/misc/drupal.js +++ b/misc/drupal.js @@ -294,7 +294,7 @@ function stopEvent(event) { else { event.returnValue = false; event.cancelBubble = true; - } + } } /** diff --git a/misc/textarea.js b/misc/textarea.js index dc9bce69c54e..e33c35bcce40 100644 --- a/misc/textarea.js +++ b/misc/textarea.js @@ -6,7 +6,7 @@ if (isJsEnabled()) { for (var i = 0; textarea = textareas[i]; ++i) { if (hasClass(textarea, 'resizable')) { if (typeof dimensions(textarea).width != 'undefined' && dimensions(textarea).width != 0) { - new textArea(textarea); + new textArea(textarea); } } } @@ -18,7 +18,7 @@ function textArea(element) { this.element = element; this.parent = this.element.parentNode; this.dimensions = dimensions(element); - + // Prepare wrapper this.wrapper = document.createElement('div'); this.wrapper.className = 'resizable-textarea'; @@ -56,7 +56,7 @@ function textArea(element) { this.grippie.style.paddingLeft = '2px'; } // Mozilla - this.element.style.MozBoxSizing = 'border-box'; + this.element.style.MozBoxSizing = 'border-box'; this.heightOffset = absolutePosition(this.grippie).y - absolutePosition(this.element).y - this.dimensions.height; } diff --git a/modules/blogapi.module b/modules/blogapi.module index 8b284b24197d..2e5fef9bca01 100644 --- a/modules/blogapi.module +++ b/modules/blogapi.module @@ -629,7 +629,7 @@ function blogapi_rsd() { function _blogapi_mt_extra(&$node, $struct) { if (is_array($node)) { $was_array = true; - $node = array2object($node); + $node = (object)$node; } // mt_allow_comments @@ -681,7 +681,7 @@ function _blogapi_mt_extra(&$node, $struct) { } if ($was_array) { - $node = object2array($node); + $node = (array)$node; } } diff --git a/modules/blogapi/blogapi.module b/modules/blogapi/blogapi.module index 8b284b24197d..2e5fef9bca01 100644 --- a/modules/blogapi/blogapi.module +++ b/modules/blogapi/blogapi.module @@ -629,7 +629,7 @@ function blogapi_rsd() { function _blogapi_mt_extra(&$node, $struct) { if (is_array($node)) { $was_array = true; - $node = array2object($node); + $node = (object)$node; } // mt_allow_comments @@ -681,7 +681,7 @@ function _blogapi_mt_extra(&$node, $struct) { } if ($was_array) { - $node = object2array($node); + $node = (array)$node; } } diff --git a/modules/comment.module b/modules/comment.module index 6bd67757ce34..3820d27d81a3 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -444,7 +444,7 @@ function comment_edit($cid) { $comment = drupal_unpack($comment); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; if (comment_access('edit', $comment)) { - return comment_form(object2array($comment)); + return comment_form((array)$comment); } else { drupal_access_denied(); @@ -1349,7 +1349,7 @@ function comment_form_add_preview($form, $edit) { $output = ''; - $comment = array2object(comment_validate($edit)); + $comment = (object)comment_validate($edit); // Attach the user and time information. if ($edit['author']) { diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 6bd67757ce34..3820d27d81a3 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -444,7 +444,7 @@ function comment_edit($cid) { $comment = drupal_unpack($comment); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; if (comment_access('edit', $comment)) { - return comment_form(object2array($comment)); + return comment_form((array)$comment); } else { drupal_access_denied(); @@ -1349,7 +1349,7 @@ function comment_form_add_preview($form, $edit) { $output = ''; - $comment = array2object(comment_validate($edit)); + $comment = (object)comment_validate($edit); // Attach the user and time information. if ($edit['author']) { diff --git a/modules/forum.module b/modules/forum.module index a298e4234ba6..8e22f6b3b7d6 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -105,10 +105,10 @@ function forum_admin() { break; case 'edit': if (arg(3) == 'forum') { - $output = forum_form_forum(object2array(taxonomy_get_term(arg(4)))); + $output = forum_form_forum((array)taxonomy_get_term(arg(4))); } else if (arg(3) == 'container') { - $output = forum_form_container(object2array(taxonomy_get_term(arg(4)))); + $output = forum_form_container((array)taxonomy_get_term(arg(4))); } break; case t('Delete'): diff --git a/modules/forum/forum.module b/modules/forum/forum.module index a298e4234ba6..8e22f6b3b7d6 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -105,10 +105,10 @@ function forum_admin() { break; case 'edit': if (arg(3) == 'forum') { - $output = forum_form_forum(object2array(taxonomy_get_term(arg(4)))); + $output = forum_form_forum((array)taxonomy_get_term(arg(4))); } else if (arg(3) == 'container') { - $output = forum_form_container(object2array(taxonomy_get_term(arg(4)))); + $output = forum_form_container((array)taxonomy_get_term(arg(4))); } break; case t('Delete'): diff --git a/modules/node.module b/modules/node.module index 46789e403767..6b033e372ca1 100644 --- a/modules/node.module +++ b/modules/node.module @@ -513,7 +513,7 @@ function node_save(&$node) { * An HTML representation of the themed node. */ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) { - $node = array2object($node); + $node = (object)$node; // Remove the delimiter (if any) that separates the teaser from the body. // TODO: this strips legitimate uses of '<!--break-->' also. @@ -1493,7 +1493,7 @@ function node_submit($node) { global $user; // Convert the node to an object, if necessary. - $node = array2object($node); + $node = (object)$node; // Auto-generate the teaser, but only if it hasn't been set (e.g. by a // module-provided 'teaser' form item). @@ -1539,7 +1539,7 @@ function node_submit($node) { */ function node_validate($node) { // Convert the node to an object, if necessary. - $node = array2object($node); + $node = (object)$node; // Make sure the body has the minimum number of words. // todo use a better word counting algorithm that will work in other languages @@ -1609,7 +1609,7 @@ function node_object_prepare(&$node) { function node_form($node) { $op = isset($_POST['op']) ? $_POST['op'] : ''; - $node = array2object($node); + $node = (object)$node; node_object_prepare($node); // Set the id of the top-level form tag @@ -1693,7 +1693,7 @@ function node_form($node) { } function node_form_add_preview($form, $edit) { - $edit = array2object($edit); + $edit = (object)$edit; node_validate($edit); $form['node_preview'] = array('#value' => node_preview($edit), '#weight' => -100); return $form; @@ -2167,7 +2167,7 @@ function node_form_alter($form_id, &$form) { */ function node_access($op, $node = NULL, $uid = NULL) { // Convert the node to an object if necessary: - $node = array2object($node); + $node = (object)$node; // If the node is in a restricted format, disallow editing. if ($op == 'update' && !filter_access($node->format)) { diff --git a/modules/node/node.module b/modules/node/node.module index 46789e403767..6b033e372ca1 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -513,7 +513,7 @@ function node_save(&$node) { * An HTML representation of the themed node. */ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) { - $node = array2object($node); + $node = (object)$node; // Remove the delimiter (if any) that separates the teaser from the body. // TODO: this strips legitimate uses of '<!--break-->' also. @@ -1493,7 +1493,7 @@ function node_submit($node) { global $user; // Convert the node to an object, if necessary. - $node = array2object($node); + $node = (object)$node; // Auto-generate the teaser, but only if it hasn't been set (e.g. by a // module-provided 'teaser' form item). @@ -1539,7 +1539,7 @@ function node_submit($node) { */ function node_validate($node) { // Convert the node to an object, if necessary. - $node = array2object($node); + $node = (object)$node; // Make sure the body has the minimum number of words. // todo use a better word counting algorithm that will work in other languages @@ -1609,7 +1609,7 @@ function node_object_prepare(&$node) { function node_form($node) { $op = isset($_POST['op']) ? $_POST['op'] : ''; - $node = array2object($node); + $node = (object)$node; node_object_prepare($node); // Set the id of the top-level form tag @@ -1693,7 +1693,7 @@ function node_form($node) { } function node_form_add_preview($form, $edit) { - $edit = array2object($edit); + $edit = (object)$edit; node_validate($edit); $form['node_preview'] = array('#value' => node_preview($edit), '#weight' => -100); return $form; @@ -2167,7 +2167,7 @@ function node_form_alter($form_id, &$form) { */ function node_access($op, $node = NULL, $uid = NULL) { // Convert the node to an object if necessary: - $node = array2object($node); + $node = (object)$node; // If the node is in a restricted format, disallow editing. if ($op == 'update' && !filter_access($node->format)) { diff --git a/modules/taxonomy.module b/modules/taxonomy.module index 5abbbe89d138..e0a6cc642da9 100644 --- a/modules/taxonomy.module +++ b/modules/taxonomy.module @@ -1126,10 +1126,10 @@ function taxonomy_admin() { break; case 'edit': if (arg(3) == 'vocabulary') { - $output = taxonomy_form_vocabulary(object2array(taxonomy_get_vocabulary(arg(4)))); + $output = taxonomy_form_vocabulary((array)taxonomy_get_vocabulary(arg(4))); } else if (arg(3) == 'term') { - $output = taxonomy_form_term(object2array(taxonomy_get_term(arg(4)))); + $output = taxonomy_form_term((array)taxonomy_get_term(arg(4))); } break; case t('Delete'): diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 5abbbe89d138..e0a6cc642da9 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -1126,10 +1126,10 @@ function taxonomy_admin() { break; case 'edit': if (arg(3) == 'vocabulary') { - $output = taxonomy_form_vocabulary(object2array(taxonomy_get_vocabulary(arg(4)))); + $output = taxonomy_form_vocabulary((array)taxonomy_get_vocabulary(arg(4))); } else if (arg(3) == 'term') { - $output = taxonomy_form_term(object2array(taxonomy_get_term(arg(4)))); + $output = taxonomy_form_term((array)taxonomy_get_term(arg(4))); } break; case t('Delete'): diff --git a/modules/upload.module b/modules/upload.module index d5c7a49bdc96..957454f99cf9 100644 --- a/modules/upload.module +++ b/modules/upload.module @@ -536,7 +536,7 @@ function _upload_image($file) { */ function upload_js() { // We only do the upload.module part of the node validation process. - $node = array2object($_POST['edit']); + $node = (object)$_POST['edit']; upload_nodeapi($node, 'validate', NULL); $form = _upload_form($node); $form = _form_builder('upload_js', $form); diff --git a/modules/upload/upload.module b/modules/upload/upload.module index d5c7a49bdc96..957454f99cf9 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -536,7 +536,7 @@ function _upload_image($file) { */ function upload_js() { // We only do the upload.module part of the node validation process. - $node = array2object($_POST['edit']); + $node = (object)$_POST['edit']; upload_nodeapi($node, 'validate', NULL); $form = _upload_form($node); $form = _form_builder('upload_js', $form); diff --git a/modules/user.module b/modules/user.module index 7e0e24688694..6d90de404791 100644 --- a/modules/user.module +++ b/modules/user.module @@ -1177,7 +1177,7 @@ function user_edit_form($uid, $edit) { // Picture/avatar: if (variable_get('user_pictures', 0)) { $form['picture'] = array('#type' => 'fieldset', '#title' => t('Picture'), '#weight' => 1); - if ($edit['picture'] && ($picture = theme('user_picture', array2object($edit)))) { + if ($edit['picture'] && ($picture = theme('user_picture', (object)$edit))) { $form['picture']['current_picture'] = array('#type' => 'markup', '#value' => $picture); $form['picture']['picture_delete'] = array('#type' => 'checkbox', '#title' => t('Delete picture'), '#description' => t('Check this box to delete your current picture.')); } @@ -1257,7 +1257,7 @@ function user_edit($category = 'account') { global $user; $account = user_load(array('uid' => arg(1))); - $edit = $_POST['op'] ? $_POST['edit'] : object2array($account); + $edit = $_POST['op'] ? $_POST['edit'] : (array)$account; if (arg(2) == 'delete') { if ($edit['confirm']) { diff --git a/modules/user/user.module b/modules/user/user.module index 7e0e24688694..6d90de404791 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1177,7 +1177,7 @@ function user_edit_form($uid, $edit) { // Picture/avatar: if (variable_get('user_pictures', 0)) { $form['picture'] = array('#type' => 'fieldset', '#title' => t('Picture'), '#weight' => 1); - if ($edit['picture'] && ($picture = theme('user_picture', array2object($edit)))) { + if ($edit['picture'] && ($picture = theme('user_picture', (object)$edit))) { $form['picture']['current_picture'] = array('#type' => 'markup', '#value' => $picture); $form['picture']['picture_delete'] = array('#type' => 'checkbox', '#title' => t('Delete picture'), '#description' => t('Check this box to delete your current picture.')); } @@ -1257,7 +1257,7 @@ function user_edit($category = 'account') { global $user; $account = user_load(array('uid' => arg(1))); - $edit = $_POST['op'] ? $_POST['edit'] : object2array($account); + $edit = $_POST['op'] ? $_POST['edit'] : (array)$account; if (arg(2) == 'delete') { if ($edit['confirm']) { diff --git a/themes/engines/phptemplate/phptemplate.engine b/themes/engines/phptemplate/phptemplate.engine index 94a40a5ba496..ac98567f7b41 100644 --- a/themes/engines/phptemplate/phptemplate.engine +++ b/themes/engines/phptemplate/phptemplate.engine @@ -244,7 +244,7 @@ function phptemplate_node($node, $teaser = 0, $page = 0) { ); // Flatten the node object's member fields. - $variables = array_merge(object2array($node), $variables); + $variables = array_merge((array)$node, $variables); // Display info only on certain node types. if (theme_get_setting('toggle_node_info_' . $node->type)) { -- GitLab