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:
parent
acd7ceb940
commit
5690c9e0a2
@ -3,6 +3,8 @@
|
|||||||
// emulates inserting a dir called HTMLPurifier into your class dir
|
// emulates inserting a dir called HTMLPurifier into your class dir
|
||||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../library/');
|
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/DirectLex.php';
|
||||||
require_once 'HTMLPurifier/Lexer/PEARSax3.php';
|
require_once 'HTMLPurifier/Lexer/PEARSax3.php';
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../library/');
|
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/DirectLex.php';
|
||||||
|
|
||||||
$input = file_get_contents('samples/Lexer/4.html');
|
$input = file_get_contents('samples/Lexer/4.html');
|
||||||
|
@ -81,19 +81,19 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
|
|||||||
|
|
||||||
// intercept non element nodes
|
// intercept non element nodes
|
||||||
|
|
||||||
if ( !($node instanceof DOMElement) ) {
|
if ( isset($node->data) ) {
|
||||||
if ($node instanceof DOMComment) {
|
if ($node->nodeType === XML_TEXT_NODE ||
|
||||||
$tokens[] = $this->factory->createComment($node->data);
|
$node->nodeType === XML_CDATA_SECTION_NODE) {
|
||||||
} elseif ($node instanceof DOMText ||
|
|
||||||
$node instanceof DOMCharacterData) {
|
|
||||||
$tokens[] = $this->factory->createText($node->data);
|
$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
|
// quite possibly, the object wasn't handled, that's fine
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We still have to make sure that the element actually IS empty
|
// We still have to make sure that the element actually IS empty
|
||||||
if (!$node->hasChildNodes()) {
|
if (!$node->childNodes->length) {
|
||||||
if ($collect) {
|
if ($collect) {
|
||||||
$tokens[] = $this->factory->createEmpty(
|
$tokens[] = $this->factory->createEmpty(
|
||||||
$node->tagName,
|
$node->tagName,
|
||||||
@ -125,13 +125,16 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
|
|||||||
* @param $attribute_list DOMNamedNodeMap of DOMAttr objects.
|
* @param $attribute_list DOMNamedNodeMap of DOMAttr objects.
|
||||||
* @returns Associative array of attributes.
|
* @returns Associative array of attributes.
|
||||||
*/
|
*/
|
||||||
protected function transformAttrToAssoc($attribute_list) {
|
protected function transformAttrToAssoc($node_map) {
|
||||||
$attribute_array = array();
|
// NamedNodeMap is documented very well, so we're using undocumented
|
||||||
// undocumented behavior
|
// features, namely, the fact that it implements Iterator and
|
||||||
foreach ($attribute_list as $key => $attr) {
|
// has a ->length attribute
|
||||||
$attribute_array[$key] = $attr->value;
|
if ($node_map->length === 0) return array();
|
||||||
|
$array = array();
|
||||||
|
foreach ($node_map as $attr) {
|
||||||
|
$array[$attr->name] = $attr->value;
|
||||||
}
|
}
|
||||||
return $attribute_array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user