Currently, _menu_append_contextual_items() starts like:

foreach ($menu_item_list as $item) {
    if (isset($item['callback'])) {
      $_menu['callbacks'][$item['path']] = array('callback' => $item['callback']);
      if (isset($item['callback arguments'])) {
        $_menu['callbacks'][$item['path']]['callback arguments'] = $item['callback arguments'];
      }
  unset($item['callback arguments']);
  unset($item['callback']);

However, it doesn't seem useful to unset these variables if they're not set. Hence a potential minor optimization avoids this useless code:

foreach ($menu_item_list as $item) {
    if (isset($item['callback'])) {
      $_menu['callbacks'][$item['path']] = array('callback' => $item['callback']);
      if (isset($item['callback arguments'])) {
        $_menu['callbacks'][$item['path']]['callback arguments'] = $item['callback arguments'];
        unset($item['callback arguments']);
      unset($item['callback']);
      }

The same seems to apply in _menu_build. The suggested patch modifies both.

CommentFileSizeAuthor
#4 menu.inc_9.patch1.36 KBfgm
menu.inc_8.patch1.3 KBfgm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fgm’s picture

Status: Active » Needs review

(forgot to set status)

Dries’s picture

The spaces look wrong? Did you properly intend the code (no tabs)? Otherwise looks good. :)

chx’s picture

Title: Minor optimization suggested for form.inc » Minor optimization suggested for menu.inc
fgm’s picture

FileSize
1.36 KB

Indeed, incorrect explanation. Here is the fix, with the missing closing brace reinstated:

  foreach ($menu_item_list as $item) {
    if (isset($item['callback'])) {
      $_menu['callbacks'][$item['path']] = array('callback' => $item['callback']);
      if (isset($item['callback arguments'])) {
        $_menu['callbacks'][$item['path']]['callback arguments'] = $item['callback arguments'];
      unset($item['callback arguments']);
      }
    unset($item['callback']);
    }

Patch rerolled just to be sure.

fgm’s picture

And, someday, I won't miss the core indenting conventions:

  foreach ($menu_item_list as $item) {
    if (isset($item['callback'])) {
      $_menu['callbacks'][$item['path']] = array('callback' => $item['callback']);
      if (isset($item['callback arguments'])) {
        $_menu['callbacks'][$item['path']]['callback arguments'] = $item['callback arguments'];
        unset($item['callback arguments']);
      }
      unset($item['callback']);
    }
Dries’s picture

Status: Needs review » Fixed

Thanks fgm. Committed your patch to CVS HEAD. Keep it coming. :)

Anonymous’s picture

Status: Fixed » Closed (fixed)