* ls2 プラグインで、常にget_source() を呼んでいる [#ra61a302] - ページ: [[BugTrack2]] - 投稿者: 名無しさん - 優先順位: 普通 - 状態: 提案 - カテゴリー: プラグイン - 投稿日: 2007-10-24 (水) 00:53:20 - バージョン: ** メッセージ [#oec27970] ls2 プラグインには、ページの内容をスキャンする必要のある、title とinclude のオプションがあります。 しかし、これらのオプションを使わない時にもget_source() を呼んでいるため、無駄が多くなっています。&br;この無駄を省くことで、上のオプションを使わない時の速度をls プラグインと同等に なるようにしましょう。 [[cvs:plugin/ls2.inc.php]] (1.25) をベースに function plugin_ls2_get_headings($page, & $params, $level, $include = FALSE) { (中略) $ret .= '<a id="list_' . $params["page_$page"] . '" href="' . $href . '" title="' . $title . '">' . $s_page . '</a>'; array_push($params['result'], $ret); - $anchor = PLUGIN_LS2_ANCHOR_ORIGIN; - $matches = array(); - foreach (get_source($page) as $line) { - if ($params['title'] && preg_match('/^(\*{1,3})/', $line, $matches)) { - $id = make_heading($line); - $level = strlen($matches[1]); - $id = PLUGIN_LS2_ANCHOR_PREFIX . $anchor++; - plugin_ls2_list_push($params, $level + strlen($level)); - array_push($params['result'], - '<li><a href="' . $href . $id . '">' . $line . '</a>'); - } else if ($params['include'] && - preg_match('/^#include\((.+)\)/', $line, $matches) && - is_page($matches[1])) - { - plugin_ls2_get_headings($matches[1], $params, $level + 1, TRUE); - } - } + if ($params['title']) { + $anchor = PLUGIN_LS2_ANCHOR_ORIGIN; + $matches = array(); + foreach (get_source($page) as $line) { + if (preg_match('/^(\*{1,3})/', $line, $matches)) { + $id = make_heading($line); + $level = strlen($matches[1]); + $id = PLUGIN_LS2_ANCHOR_PREFIX . $anchor++; + plugin_ls2_list_push($params, $level + strlen($level)); + array_push($params['result'], + '<li><a href="' . $href . $id . '">' . $line . '</a>'); + } + } + } else if ($params['include']) { + $matches = array(); + foreach (get_source($page) as $line) { + if (preg_match('/^#include\((.+)\)/', $line, $matches) && + is_page($matches[1])) + { + plugin_ls2_get_headings($matches[1], $params, $level + 1, TRUE); + } + } + } } -------- #comment