iliaa Tue May 25 15:07:13 2004 EDT
Modified files:
/livedocs livedoc_funcs.php pregenerate.php style_mapping.php
xml_classes5.php
Log:
Various optimizations, these gives us about 15%-20% speed boost.
http://cvs.php.net/diff.php/livedocs/livedoc_funcs.php?r1=1.2&r2=1.3&ty=u
Index: livedocs/livedoc_funcs.php
diff -u livedocs/livedoc_funcs.php:1.2 livedocs/livedoc_funcs.php:1.3
--- livedocs/livedoc_funcs.php:1.2 Tue May 25 11:24:46 2004
+++ livedocs/livedoc_funcs.php Tue May 25 15:07:13 2004
@@ -123,7 +123,7 @@
$title = lookup_title($item);
$fulltitle = $title;
- if (strlen($title) > 25) {
+ if (isset($title{25})) {
$ftitle = " title='$title'";
$title = substr($title, 0, 22). '...';
} else {
@@ -161,33 +161,23 @@
$sanity = 0;
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]);
- foreach ($entities_to_find as $ent) {
- if (isset($entity_cache[$ent])) {
- $entities['&' . $ent . ';'] = $entity_cache[$ent];
- unset($entities_to_find[$ent]);
- }
+ $q = sqlite_query($idx, "SELECT entid, value from ents where is_file=0
and entid in ('" . implode("','", $matches[1]) . "') GROUP BY entid");
+ if (!$q) {
+ break;
}
-
- if (count($entities_to_find)) {
- $ents = implode("','", $entities_to_find);
- $q = sqlite_query($idx, "SELECT entid, value from ents where
is_file=0 and entid in ('" . $ents . "')");
- if ($q) {
- while ($r = sqlite_fetch_array($q, SQLITE_NUM)) {
- $entities['&' . $r[0] . ';'] = $r[1];
- $entities_cache[$r[0]] = $r[1];
- }
- }
+ $src = $dst = array();
+
+ while ($r = sqlite_fetch_array($q, SQLITE_NUM)) {
+ $src[] = '&' . $r[0] . ';';
+ $dst[] = $r[1];
}
- if (!count($entities))
+ if (empty($src)) {
break;
+ }
- /* substitute */
- $data = strtr($data, $entities);
-
- } while ($sanity++ < 5);
+ $data = str_replace($src, $dst, $data);
+ }
return $data;
}
@@ -210,10 +200,10 @@
$lang_rev = 0;
$data = @file_get_contents($filename);
- if (strlen($data) == 0 && strlen($fallback_filename)) {
+ if (!$data && $fallback_filename) {
$data = @file_get_contents($fallback_filename);
- if (strlen($data) == 0) {
+ if (!$data) {
$data = "<warning>permissions problem for
$filename?</warning>";
}
http://cvs.php.net/diff.php/livedocs/pregenerate.php?r1=1.1&r2=1.2&ty=u
Index: livedocs/pregenerate.php
diff -u livedocs/pregenerate.php:1.1 livedocs/pregenerate.php:1.2
--- livedocs/pregenerate.php:1.1 Tue May 25 07:33:48 2004
+++ livedocs/pregenerate.php Tue May 25 15:07:13 2004
@@ -6,6 +6,8 @@
* So, only run this with PHP 5 if you value your RAM!
*/
+//apd_set_pprof_trace();
+
define('LIVEDOC_SOURCE', dirname(__FILE__));
include LIVEDOC_SOURCE . '/livedoc_funcs.php';
@@ -24,7 +26,7 @@
$nav_time = 0;
$load_time = 0;
-while ($page_row = sqlite_fetch_array($ids_and_pages)) {
+while ($page_row = sqlite_fetch_array($ids_and_pages, SQLITE_NUM)) {
if ($last_file_name == $page_row[1])
continue;
@@ -107,6 +109,11 @@
if ($__node_count > 0) {
fwrite(STDERR, "nodes: $__node_count\n"); fflush(STDERR);
}
+/* XXX: dev limiter
+ if ($number_processed > 10) {
+ break;
+ }
+*/
}
$elapsed = microtime(true) - $start_time;
http://cvs.php.net/diff.php/livedocs/style_mapping.php?r1=1.15&r2=1.16&ty=u
Index: livedocs/style_mapping.php
diff -u livedocs/style_mapping.php:1.15 livedocs/style_mapping.php:1.16
--- livedocs/style_mapping.php:1.15 Sun May 23 04:58:01 2004
+++ livedocs/style_mapping.php Tue May 25 15:07:13 2004
@@ -18,7 +18,7 @@
// | Helper functions for formatting elements |
// +----------------------------------------------------------------------+
//
-// $Id: style_mapping.php,v 1.15 2004/05/23 08:58:01 wez Exp $
+// $Id: style_mapping.php,v 1.16 2004/05/25 19:07:13 iliaa Exp $
// almost XPATH.. ;-)
$map = array(
@@ -159,7 +159,7 @@
$vers = '';
if (substr($current_page, 0, 9) == 'function.') {
- $func_name = sqlite_escape_string(strtr(substr($current_page, 9), '-',
'_'));
+ $func_name = sqlite_escape_string(str_replace('-', '_',
substr($current_page, 9)));
$q = sqlite_single_query($idx, "SELECT versinfo FROM funcs where
funcname='$func_name'");
if ($q) {
$vers = sprintf('<div class="versinfo">%s</div>', $q);
@@ -249,12 +249,7 @@
{
global $current_page, $lang, $idx;
- $replace = array('_' => '-',
- '::' => '-',
- '->' => '-');
-
- $itemid = strtr($node->content, $replace);
- $itemid = strtolower(strtr($itemid, array('---' => '-')));
+ $itemid = strtolower(str_replace(array('_', '::', '->', '---'),
array('-','-','-', '-'), $node->content));
if (isset($node->attributes['class'])) {
$class = 'method';
@@ -299,7 +294,7 @@
{
global $lang;
- $link = strtr($matches[1], array('_' => '-'));
+ $link = str_replace('_', '-', $matches[1]);
$link = WEBBASE . (FORCE_DYNAMIC ? "?l=$lang&q=function.$link" :
"$lang/function.$link.html");
return '<a class="phpfunc" href="' . $link . '">' . $matches[1] . '</a>(';
}
@@ -376,15 +371,16 @@
$params = "";
$optclose = "";
- for ($i = 2; $i < count($node->children); $i++) {
+ $c = count($node->children);
+ for ($i = 2; $i < $c; $i++) {
$k = $node->children[$i];
- if (strlen($k->tagname) == 0 || $k->tagname == 'void') {
+ if (!$k->tagname || $k->tagname == 'void') {
continue;
}
$p = '';
- if (strlen(trim(strip_tags($params)))) {
+ if (trim(strip_tags($params))) {
$p .= ',';
}
@@ -396,7 +392,7 @@
}
}
- if (strlen($p)) {
+ if ($p) {
$p .= ' ';
}
@@ -439,7 +435,8 @@
$foot = "</div>}\n</div>";
$body = "";
- for ($i = 1; $i < count($node->children); $i++) {
+ $c = count($node->children);
+ for ($i = 1; $i < $c; $i++) {
$k = $node->children[$i];
switch ($k->tagname) {
@@ -464,7 +461,8 @@
$html = "<div class=\"funcsynopsis\">";
/* for each prototype in the synopsis */
- for ($proto = 0; $proto < count($node->children); $proto++) {
+ $c = count($node->children);
+ for ($proto = 0; $proto < $c; $proto++) {
$p = $node->children[$proto];
if ($p->tagname != 'funcprototype')
@@ -480,7 +478,8 @@
$rettype = "";
$funcname = "";
- for ($i = 0; $i < count($funcdef->children); $i++) {
+ $c2 = count($funcdef->children);
+ for ($i = 0; $i < $c2; $i++) {
$k = $funcdef->children[$i];
switch($k->tagname) {
case '':
@@ -502,7 +501,8 @@
$params = "";
$optclose = "";
- for ($i = 1; $i < count($p->children); $i++) {
+ $c2 = count($p->children);
+ for ($i = 1; $i < $c2; $i++) {
$def = $p->children[$i];
if ($def->tagname != 'paramdef') {
continue;
@@ -510,8 +510,9 @@
$paramhtml = "";
$paramtype = "";
$param = null;
-
- for ($j = 0; $j < count($def->children); $j++) {
+
+ $c3 = count($def->children);
+ for ($j = 0; $j < $c; $j++) {
$k = $def->children[$j];
switch($k->tagname) {
case 'parameter':
http://cvs.php.net/diff.php/livedocs/xml_classes5.php?r1=1.2&r2=1.3&ty=u
Index: livedocs/xml_classes5.php
diff -u livedocs/xml_classes5.php:1.2 livedocs/xml_classes5.php:1.3
--- livedocs/xml_classes5.php:1.2 Tue May 25 11:24:46 2004
+++ livedocs/xml_classes5.php Tue May 25 15:07:13 2004
@@ -19,7 +19,7 @@
// | PHP 5 style |
// +----------------------------------------------------------------------+
//
-// $Id: xml_classes5.php,v 1.2 2004/05/25 15:24:46 wez Exp $
+// $Id: xml_classes5.php,v 1.3 2004/05/25 19:07:13 iliaa Exp $
class Node { /* {{{ */
@@ -33,7 +33,7 @@
function transform($map)
{
- if (strlen($this->tagname) == 0) {
+ if (!$this->tagname) {
return htmlspecialchars($this->content, ENT_NOQUOTES);
}
@@ -46,7 +46,8 @@
if ($mapent[0][0] == $this->tagname) {
$n = $this->parent;
$match = true;
- for ($i = 1; $i < count($mapent[0]); $i++) {
+ $c = count($mapent[0]);
+ for ($i = 1; $i < $c; $i++) {
if ($n->tagname != $mapent[0][$i]) {
$match = false;
break;
@@ -69,7 +70,7 @@
$anchor = '';
}
- if (strlen($tagname)) {
+ if ($tagname) {
$xml = '<' . $tagname;
foreach ($attributes as $name => $value) {
$xml .= ' ' . $name . '="' . htmlspecialchars($value)
. '"';
@@ -80,33 +81,32 @@
$content = "";
- if (count($this->children) == 0) {
+ if (empty($this->children)) {
- if (strlen($tagname) == 0) {
+ if (!$tagname) {
return '';
}
- if (strlen($this->content)) {
+ if ($this->content) {
$content = htmlspecialchars($this->content,
ENT_NOQUOTES);
}
} else {
- for ($i = 0; $i < count($this->children); $i++) {
- $child = $this->children[$i];
+ foreach ($this->children as &$child) {
$content .= $child->transform($map);
}
}
- if (strlen($tagname)) {
+ if ($tagname) {
$xml .= '>';
}
- if ($tagname == 'th' && strlen($content) == 0) {
+ if ($tagname == 'th' && !$content) {
$content = ' ';
}
$xml .= $anchor;
$xml .= $content;
- if (strlen($tagname)) {
+ if ($tagname) {
$xml .= '</' . $tagname . '>';
}
@@ -118,13 +118,14 @@
if (isset($this->attributes['id']) && $this->attributes['id'] == $id) {
return $node;
}
- // look for children that match
- for ($i = 0; $i < count($this->children); $i++) {
- $x = $this->select_node($this->children[$i], $id);
+ /* look for children that match */
+ foreach ($this->children as &$child) {
+ $x = $this->select_node($child, $id);
if (is_object($x)) {
return $x;
}
}
+
return null;
}
@@ -156,7 +157,7 @@
function as_xml()
{
- if (strlen($this->tagname) == 0) {
+ if (!$this->tagname) {
return htmlspecialchars($this->content, ENT_NOQUOTES);
}
@@ -164,16 +165,16 @@
foreach ($this->attributes as $name => $value) {
$xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"';
}
- if (count($this->children) == 0) {
- if (strlen($this->content) == 0) {
+ if (empty($this->children)) {
+ if (!$this->content) {
$xml .= '/>';
} else {
$xml .= '>' . htmlspecialchars($this->content,
ENT_NOQUOTES) . '</' . $this->tagname . '>';
}
} else {
$xml .= '>';
- for ($i = 0; $i < count($this->children); $i++) {
- $xml .= $this->children[$i]->as_xml();
+ foreach ($this->children as &$child) {
+ $xml .= $child->as_xml();
}
$xml .= '</' . $this->tagname . '>';
}
@@ -182,8 +183,8 @@
function add_child($child)
{
- if (count($this->children) == 0 && strlen($this->content)) {
- if (strlen(trim($this->content)) > 0) {
+ if (empty($this->children) && $this->content) {
+ if (trim($this->content)) {
// promote content to an anonymous cdata node
$node = new Node("", array());
$node->content = $this->content;
@@ -196,7 +197,7 @@
function add_cdata($data)
{
- if (count($this->children) == 0) {
+ if (empty($this->children)) {
$this->content .= $data;
} else {
$node = new Node("", array());
@@ -211,14 +212,11 @@
function release()
{
- for ($i = 0; $i < count($this->children); $i++) {
- if (is_object($this->children[$i])) {
- $this->children[$i]->release();
+ foreach ($this->children as &$child) {
+ if (is_object($child)) {
+ $child->release();
}
- }
-
- for ($i = 0; $i < count($this->children); $i++) {
- $this->children[$i] = null;
+ $child = null;
}
$this->parent = null;
@@ -250,7 +248,7 @@
function DocBookToHTML($xml, $id = null)
{
- if (strlen($xml) == 0) {
+ if (!$xml) {
return;
}
@@ -309,7 +307,7 @@
function _as_xml($node)
{
- if (strlen($node->tagname) == 0) {
+ if (!$node->tagname) {
return htmlspecialchars($node->content, ENT_NOQUOTES);
}
@@ -317,16 +315,16 @@
foreach ($node->attributes as $name => $value) {
$xml .= ' ' . $name . '="' . htmlspecialchars($value) . '"';
}
- if (count($node->children) == 0) {
- if (strlen($node->content) == 0) {
+ if (empty($node->children)) {
+ if (!$node->content) {
$xml .= '/>';
} else {
$xml .= '>' . htmlspecialchars($node->content,
ENT_NOQUOTES) . '</' . $node->tagname . '>';
}
} else {
$xml .= '>';
- for ($i = 0; $i < count($node->children); $i++) {
- $xml .= $this->_as_xml($node->children[$i]);
+ foreach ($node->children as &$child) {
+ $xml .= $this->_as_xml($child);
}
$xml .= '</' . $node->tagname . '>';
}