From f0969501a889abc254fdc7c8323f63053761fff3 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 20 Sep 2010 14:05:57 +0000 Subject: it_html speedup --- it_html.class | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'it_html.class') diff --git a/it_html.class b/it_html.class index be13fe4..4c1fbae 100644 --- a/it_html.class +++ b/it_html.class @@ -72,7 +72,15 @@ function it_html($p = array()) foreach (array_merge(explode(',', $this->p['tags']), explode(',', $this->p['moretags'])) as $func) { if (!function_exists($func) && $func) - $code[$func] = "function $func() { \$args = func_get_args(); return \$GLOBALS['{$this->p['name']}']->_tag('$func', \$args); }"; + { + if (!$this->p['prettyprint'] && $this->p['charset'] == "iso-8859-1" && $this->p['htmltype'] == "html" && !$GLOBALS['debug_srclines']) + { + $emptycloser = preg_match('/^(a|div|iframe|pre|script|span|td|textarea)$/i', $func) ? "" : ""; + $code[$func] = "function $func() { \$args = func_get_args(); return \$GLOBALS['{$this->p['name']}']->_tag_fast('$func', \$args, '$emptycloser'); }"; + } + else + $code[$func] = "function $func() { \$args = func_get_args(); return \$GLOBALS['{$this->p['name']}']->_tag('$func', \$args); }"; + } } # Create global functions for it_html methods @@ -250,6 +258,32 @@ function _parse_args($args) /** * INTERNAL: Create html tag from name and args array (the arguments of the parent function) */ +function _tag_fast($name, $args, $emptycloser) +{ + foreach ($args as $arg) + { + if (is_array($arg)) + { + foreach ($arg as $key => $value) + { + if (is_string($value)) + { + if (preg_match('/[<>&"\x00-\x08\x0a-\x0c\x0e-\x1f\x80-\x9f]/', $value)) # WARNING: copy/pasted from Q() + $attrs .= " $key=\"" . str_replace("\n", " ", it_html::latinize($value)) . '"'; + else + $attrs .= " $key=\"$value\""; + } + else if ($value === true) + $attrs .= " $key"; + } + } + else + $content .= $arg; + } + + return isset($content) ? "<$name$attrs>$content" : "<$name$attrs>$content$emptycloser"; +} + function _tag($name, $args) { list($data, $attr) = $this->_parse_args($args); -- cgit v1.2.3