iliaa Mon May 24 16:59:28 2004 EDT
Modified files: /livedocs livedoc.php Log: Optimizations: part #3. http://cvs.php.net/diff.php/livedocs/livedoc.php?r1=1.105&r2=1.106&ty=u Index: livedocs/livedoc.php diff -u livedocs/livedoc.php:1.105 livedocs/livedoc.php:1.106 --- livedocs/livedoc.php:1.105 Mon May 24 16:42:43 2004 +++ livedocs/livedoc.php Mon May 24 16:59:28 2004 @@ -18,7 +18,7 @@ // | Generate an HTML version of a phpdoc/docbook page on the fly | // +----------------------------------------------------------------------+ // -// $Id: livedoc.php,v 1.105 2004/05/24 20:42:43 iliaa Exp $ +// $Id: livedoc.php,v 1.106 2004/05/24 20:59:28 iliaa Exp $ define('LIVEDOC_SOURCE', dirname(__FILE__)); include LIVEDOC_SOURCE . '/common.php'; @@ -230,7 +230,7 @@ $idx = $GLOBALS['fb_idx']; } - if ($fileid !== null) { /* determine the first node within that file */ + if (!$fileid) { /* determine the first node within that file */ $firstid = sqlite_single_query($idx, "SELECT id from idents where fileid='$fileid' LIMIT 1"); } @@ -267,11 +267,12 @@ $title = substr($title, 0, 22). '...'; } else { $ftitle = ""; + if (!$title) { + $title = $item . ' [?]'; + $nolink = TRUE; + } } - if (empty($title)) { - $title = $item. ' [?]'; - $nolink = TRUE; - } + if ($item == $current_page) { $current_page_title = $title; $title = "<b>$title</b>"; @@ -292,27 +293,25 @@ function bind_entities($data) { global $idx; - $entities = array(); $sanity = 0; - do { - $ent_count = preg_match_all('/&([a-zA-Z0-9.-]+);/sm', $data, $matches); - if ($ent_count == 0) { - break; - } - + while (($ent_count = preg_match_all('/&([a-zA-Z0-9.-]+);/sm', $data, $matches)) && $sanity++ < 5) { /* now collect their values */ - $entities_to_find = array_unique($matches[1]); - $ents = implode("','", $entities_to_find); + $ents = implode("','", array_unique($matches[1])); $r = sqlite_array_query($idx, "SELECT entid, value from ents where entid in ('" . $ents . "')", SQLITE_NUM); if ($r) { + $src = $dst = array(); foreach ($r as $v) { - $entities['&' . $v[0] . ';'] = $v[1]; + $src[] = '&' . $v[0] . ';'; + $dst[] = $v[1]; } /* substitute */ - $data = strtr($data, $entities); + $data = str_replace($src, $dst, $data); + } else { + /* no matching entities, no point in looping further */ + break; } - } while ($sanity++ < 5); + } return $data; } @@ -460,21 +459,29 @@ $stag = 'function'; $etag = 'function'; - if (count($parts) == 4) { - $id = 'function.' . $parts[3]; - $func_name = lookup_title($id); - } elseif ($parts[3] == 'class' && count($parts) == 5) { - $id = 'class.' . $parts[4]; - $func_name = strtr($parts[4], array('-'=>'_')); - $stag = "xref linkend=\"$id\""; - $etag = "xref"; - } else { - /* some weird node type we don't understand */ - $id = $ref; - $func_name = 'Unknown ??'; + switch (count($parts)) { + case 4: + $id = 'function.' . $parts[3]; + $func_name = lookup_title($id); + break; + + case 5: + if ($parts[3] == 'class') { + $id = 'class.' . $parts[4]; + $func_name = str_replace('-', '_', $parts[4]); + $stag = "xref linkend=\"$id\""; + $etag = "xref"; + break; + } + /* fall through */ + + default: + /* some weird node type we don't understand */ + $id = $ref; + $func_name = 'Unknown ??'; } - - if($parts[3] == 'class') { + + if ($parts[3] == 'class') { $title = ' - ' . lookup_title($id) . ' class'; } else { $title = ' - ' . bind_entities(sqlite_single_query($GLOBALS['idx'], "SELECT descr from toc where docbook_id='$id'"));