From eb28074aa33f4768f84fe75ae2c3826f2dbe55af Mon Sep 17 00:00:00 2001 From: Steven Wittens <steven@10.no-reply.drupal.org> Date: Wed, 10 Jan 2007 23:30:07 +0000 Subject: [PATCH] #108320: Form API optimization, don't call element_sort unless needed. --- includes/common.inc | 6 +++++- includes/form.inc | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index b55384e2a6b3..acd66a789cf1 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2113,7 +2113,11 @@ function drupal_render(&$elements) { } $content = ''; - uasort($elements, "_element_sort"); + // Either the elements did not go through form_builder or one of the children + // has a #weight. + if (!isset($elements['#sorted'])) { + uasort($elements, "_element_sort"); + } if (!isset($elements['#children'])) { $children = element_children($elements); /* Render all the children that use a theme function */ diff --git a/includes/form.inc b/includes/form.inc index e2a3b06ba503..7eb46188312d 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -755,8 +755,11 @@ function form_builder($form_id, $form) { form_set_value($form, $form['#value']); } + // We start off assuming all form elements are in the correct order. + $form['#sorted'] = TRUE; + // Recurse through all child elements. - $count = 0; + $count = 0; foreach (element_children($form) as $key) { $form[$key]['#post'] = $form['#post']; $form[$key]['#programmed'] = $form['#programmed']; @@ -780,6 +783,10 @@ function form_builder($form_id, $form) { if (!isset($form[$key]['#weight'])) { $form[$key]['#weight'] = $count/1000; } + else { + // If one the child elements has a weight then we will need to sort later. + unset($form['#sorted']); + } $form[$key] = form_builder($form_id, $form[$key]); $count++; } -- GitLab