diff options
author | Matt Farina <[email protected]> | 2013-04-24 03:36:52 -0400 |
---|---|---|
committer | Matt Farina <[email protected]> | 2013-04-24 03:36:52 -0400 |
commit | 8250662c81b3b850bf49c516835a2ac3f7b6a61f (patch) | |
tree | 80d9e8635bd781cce5b86c922c3733628b886565 /src/HTML5 | |
parent | b799bebf89842830ffedbdd109014b224a74800f (diff) |
Moved back to array lookups for html5 elements. This is SIGNIFICANTLY faster then the regular expressions and twice as fast as the next fastest method I tested.
Diffstat (limited to 'src/HTML5')
-rw-r--r-- | src/HTML5/Elements.php | 222 | ||||
-rw-r--r-- | src/HTML5/Serializer/Traverser.php | 44 |
2 files changed, 153 insertions, 113 deletions
diff --git a/src/HTML5/Elements.php b/src/HTML5/Elements.php index 30e3dc9..a36f6ac 100644 --- a/src/HTML5/Elements.php +++ b/src/HTML5/Elements.php @@ -1,120 +1,124 @@ <?php -class Element { +class Elements { const TEXT_RAW = 0x01; const TEXT_RCDATA = 0x02; const OMIT_START = 0x0a; const OMIT_END = 0x0b; + /** + * The HTML5 elements. + * @var array + */ public static $properties = array( - "a" => 0, - "abbr" => 0, - "address" => 0, - "area" => 0, - "article" => 0, - "aside" => 0, - "audio" => 0, - "b" => 0, - "base" => 0, - "bdi" => 0, - "bdo" => 0, - "blockquote" => 0, - "body" => 0, - "br" => 0, - "button" => 0, - "canvas" => 0, - "caption" => 0, - "cite" => 0, - "code" => 0, - "col" => 0, - "colgroup" => 0, - "command" => 0, - "datalist" => 0, - "dd" => 0, - "del" => 0, - "details" => 0, - "dfn" => 0, - "dialog" => 0, - "div" => 0, - "dl" => 0, - "dt" => 0, - "em" => 0, - "embed" => 0, - "fieldset" => 0, - "figcaption" => 0, - "figure" => 0, - "footer" => 0, - "form" => 0, - "h1" => 0, - "h2" => 0, - "h3" => 0, - "h4" => 0, - "h5" => 0, - "h6" => 0, - "head" => 0, - "header" => 0, - "hgroup" => 0, - "hr" => 0, - "html" => 0, - "i" => 0, - "iframe" => 0, - "img" => 0, - "input" => 0, - "kbd" => 0, - "ins" => 0, - "keygen" => 0, - "label" => 0, - "legend" => 0, - "li" => 0, - "link" => 0, - "map" => 0, - "mark" => 0, - "menu" => 0, - "meta" => 0, - "meter" => 0, - "nav" => 0, - "noscript" => 0, - "object" => 0, - "ol" => 0, - "optgroup" => 0, - "option" => 0, - "output" => 0, - "p" => 0, - "param" => 0, - "pre" => 0, - "progress" => 0, - "q" => 0, - "rp" => 0, - "rt" => 0, - "ruby" => 0, - "s" => 0, - "samp" => 0, - "script" => 0, - "section" => 0, - "select" => 0, - "small" => 0, - "source" => 0, - "span" => 0, - "strong" => 0, - "style" => 0, - "sub" => 0, - "summary" => 0, - "sup" => 0, - "table" => 0, - "tbody" => 0, - "td" => 0, - "textarea" => 0, - "tfoot" => 0, - "th" => 0, - "thead" => 0, - "time" => 0, - "title" => 0, - "tr" => 0, - "track" => 0, - "u" => 0, - "ul" => 0, - "var" => 0, - "wbr" => 0, + "a" => 1, + "abbr" => 1, + "address" => 1, + "area" => 1, + "article" => 1, + "aside" => 1, + "audio" => 1, + "b" => 1, + "base" => 1, + "bdi" => 1, + "bdo" => 1, + "blockquote" => 1, + "body" => 1, + "br" => 1, + "button" => 1, + "canvas" => 1, + "caption" => 1, + "cite" => 1, + "code" => 1, + "col" => 1, + "colgroup" => 1, + "command" => 1, + "datalist" => 1, + "dd" => 1, + "del" => 1, + "details" => 1, + "dfn" => 1, + "dialog" => 1, + "div" => 1, + "dl" => 1, + "dt" => 1, + "em" => 1, + "embed" => 1, + "fieldset" => 1, + "figcaption" => 1, + "figure" => 1, + "footer" => 1, + "form" => 1, + "h1" => 1, + "h2" => 1, + "h3" => 1, + "h4" => 1, + "h5" => 1, + "h6" => 1, + "head" => 1, + "header" => 1, + "hgroup" => 1, + "hr" => 1, + "html" => 1, + "i" => 1, + "iframe" => 1, + "img" => 1, + "input" => 1, + "kbd" => 1, + "ins" => 1, + "keygen" => 1, + "label" => 1, + "legend" => 1, + "li" => 1, + "link" => 1, + "map" => 1, + "mark" => 1, + "menu" => 1, + "meta" => 1, + "meter" => 1, + "nav" => 1, + "noscript" => 1, + "object" => 1, + "ol" => 1, + "optgroup" => 1, + "option" => 1, + "output" => 1, + "p" => 1, + "param" => 1, + "pre" => 1, + "progress" => 1, + "q" => 1, + "rp" => 1, + "rt" => 1, + "ruby" => 1, + "s" => 1, + "samp" => 1, + "script" => 1, + "section" => 1, + "select" => 1, + "small" => 1, + "source" => 1, + "span" => 1, + "strong" => 1, + "style" => 1, + "sub" => 1, + "summary" => 1, + "sup" => 1, + "table" => 1, + "tbody" => 1, + "td" => 1, + "textarea" => 1, + "tfoot" => 1, + "th" => 1, + "thead" => 1, + "time" => 1, + "title" => 1, + "tr" => 1, + "track" => 1, + "u" => 1, + "ul" => 1, + "var" => 1, + "wbr" => 1, ); } diff --git a/src/HTML5/Serializer/Traverser.php b/src/HTML5/Serializer/Traverser.php index a066517..735e413 100644 --- a/src/HTML5/Serializer/Traverser.php +++ b/src/HTML5/Serializer/Traverser.php @@ -12,7 +12,31 @@ namespace HTML5\Serializer; */ class Traverser { - static $block_elements = 'html|body|head|p|div|h[1-6]|title|script|link|meta|section|article|table|tbody|tr|th|td'; + static $block_elements = array( + 'html' => 1, + 'body' => 1, + 'head' => 1, + 'p' => 1, + 'div' => 1, + 'h1' => 1, + 'h2' => 1, + 'h3' => 1, + 'h4' => 1, + 'h5' => 1, + 'h6' => 1, + 'title' => 1, + 'script' => 1, + 'link' => 1, + 'meta' => 1, + 'section' => 1, + 'article' => 1, + 'table' => 1, + 'tbody' => 1, + 'tr' => 1, + 'th' => 1, + 'td' => 1, + //'form' => 1, + ); // TODO: Refactor this into an element mask. static $literal_elements = array( @@ -33,7 +57,19 @@ class Traverser { * input, keygen, link, meta, param, source, track or wbr element, then * continue on to the next child node at this point. */ - static $unary_elements = 'area|base|basefont|bgsound|br|col|command|embed|frame|hr|img'; + static $unary_elements = array( + 'area' => 1, + 'base' => 1, + 'basefont' => 1, + 'bgsound' => 1, + 'br' => 1, + 'col' => 1, + 'command' => 1, + 'embed' => 1, + 'frame' => 1, + 'hr' => 1, + 'img' => 1, + ); /** Namespaces that should be treated as "local" to HTML5. */ static $local_ns = array( @@ -264,7 +300,7 @@ class Traverser { * True if Unary and false otherwise. */ protected function isUnary($name) { - return (bool)preg_match('/^(' . self::$unary_elements . ')$/i', $name); + return isset(self::$unary_elements[$name]); } /** @@ -277,7 +313,7 @@ class Traverser { * If the element is block level or not. */ protected function isBlock($name) { - return (bool)preg_match('/^(' . self::$block_elements . ')$/i', $name); + return isset(self::$block_elements[$name]); } /** |