0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 16:31:53 +00:00

Further optimization: 20% - 12%. Also fixed broken benchmarks.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@266 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-08-15 21:19:45 +00:00
parent acd7ceb940
commit 5690c9e0a2
3 changed files with 19 additions and 12 deletions

View File

@ -3,6 +3,8 @@
// emulates inserting a dir called HTMLPurifier into your class dir
set_include_path(get_include_path() . PATH_SEPARATOR . '../library/');
require_once 'HTMLPurifier/ConfigDef.php';
require_once 'HTMLPurifier/Config.php';
require_once 'HTMLPurifier/Lexer/DirectLex.php';
require_once 'HTMLPurifier/Lexer/PEARSax3.php';

View File

@ -2,6 +2,8 @@
set_include_path(get_include_path() . PATH_SEPARATOR . '../library/');
require_once 'HTMLPurifier/ConfigDef.php';
require_once 'HTMLPurifier/Config.php';
require_once 'HTMLPurifier/Lexer/DirectLex.php';
$input = file_get_contents('samples/Lexer/4.html');

View File

@ -81,19 +81,19 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
// intercept non element nodes
if ( !($node instanceof DOMElement) ) {
if ($node instanceof DOMComment) {
$tokens[] = $this->factory->createComment($node->data);
} elseif ($node instanceof DOMText ||
$node instanceof DOMCharacterData) {
if ( isset($node->data) ) {
if ($node->nodeType === XML_TEXT_NODE ||
$node->nodeType === XML_CDATA_SECTION_NODE) {
$tokens[] = $this->factory->createText($node->data);
} elseif ($node->nodeType === XML_COMMENT_NODE) {
$tokens[] = $this->factory->createComment($node->data);
}
// quite possibly, the object wasn't handled, that's fine
return;
}
// We still have to make sure that the element actually IS empty
if (!$node->hasChildNodes()) {
if (!$node->childNodes->length) {
if ($collect) {
$tokens[] = $this->factory->createEmpty(
$node->tagName,
@ -125,13 +125,16 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
* @param $attribute_list DOMNamedNodeMap of DOMAttr objects.
* @returns Associative array of attributes.
*/
protected function transformAttrToAssoc($attribute_list) {
$attribute_array = array();
// undocumented behavior
foreach ($attribute_list as $key => $attr) {
$attribute_array[$key] = $attr->value;
protected function transformAttrToAssoc($node_map) {
// NamedNodeMap is documented very well, so we're using undocumented
// features, namely, the fact that it implements Iterator and
// has a ->length attribute
if ($node_map->length === 0) return array();
$array = array();
foreach ($node_map as $attr) {
$array[$attr->name] = $attr->value;
}
return $attribute_array;
return $array;
}
}