rrichards Tue Nov 1 18:21:29 2005 EDT
Modified files:
/php-src/ext/simplexml simplexml.c
/php-src/ext/simplexml/tests 025.phpt
Log:
optimize sxe_add_registered_namespaces
add only first encountered prefixes to namespace arrays
update test
http://cvs.php.net/diff.php/php-src/ext/simplexml/simplexml.c?r1=1.174&r2=1.175&ty=u
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.174
php-src/ext/simplexml/simplexml.c:1.175
--- php-src/ext/simplexml/simplexml.c:1.174 Tue Nov 1 06:53:12 2005
+++ php-src/ext/simplexml/simplexml.c Tue Nov 1 18:21:28 2005
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: simplexml.c,v 1.174 2005/11/01 11:53:12 helly Exp $ */
+/* $Id: simplexml.c,v 1.175 2005/11/01 23:21:28 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -1106,7 +1106,10 @@
static inline void sxe_add_namespace_name(zval *return_value, xmlNsPtr ns)
{
- add_assoc_string(return_value, SXE_NS_PREFIX(ns), (char*)ns->href, 1);
+ char *prefix = SXE_NS_PREFIX(ns);
+ if (zend_hash_exists(Z_ARRVAL_P(return_value), prefix, strlen(prefix) +
1) == 0) {
+ add_assoc_string(return_value, prefix, (char*)ns->href, 1);
+ }
}
static void sxe_add_namespaces(php_sxe_object *sxe, xmlNodePtr node, zend_bool
recursive, zval *return_value TSRMLS_DC) /* {{{ */
@@ -1167,25 +1170,27 @@
}
/* }}} */
-static void sxe_add_registered_namespaces(php_sxe_object *sxe, xmlDocPtr doc,
xmlNodePtr node, zend_bool recursive, zval *return_value TSRMLS_DC) /* {{{ */
+static void sxe_add_registered_namespaces(php_sxe_object *sxe, xmlNodePtr
node, zend_bool recursive, zval *return_value TSRMLS_DC) /* {{{ */
{
- xmlNsPtr *ns = xmlGetNsList(doc, node);
-
- while (ns && ns[0]) {
- sxe_add_namespace_name(return_value, ns[0]);
- ns++;
- }
+ xmlNsPtr ns;
- if (recursive) {
- node = node->children;
- while (node) {
- sxe_add_registered_namespaces(sxe, doc, node,
recursive, return_value TSRMLS_CC);
- node = node->next;
+ if (node->type == XML_ELEMENT_NODE) {
+ ns = node->nsDef;
+ while (ns != NULL) {
+ sxe_add_namespace_name(return_value, ns);
+ ns = ns->next;
+ }
+ if (recursive) {
+ node = node->children;
+ while (node) {
+ sxe_add_registered_namespaces(sxe, node,
recursive, return_value TSRMLS_CC);
+ node = node->next;
+ }
}
}
}
-/* {{{ proto string SimpleXMLElement::getDocNamespaces([bool recursve])
+/* {{{ proto string SimpleXMLElement::getDocNamespaces([bool recursive])
Return all namespaces registered with document */
SXE_METHOD(getDocNamespaces)
{
@@ -1200,7 +1205,7 @@
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
- sxe_add_registered_namespaces(sxe, (xmlDocPtr)sxe->document->ptr,
xmlDocGetRootElement((xmlDocPtr)sxe->document->ptr), recursive, return_value
TSRMLS_CC);
+ sxe_add_registered_namespaces(sxe,
xmlDocGetRootElement((xmlDocPtr)sxe->document->ptr), recursive, return_value
TSRMLS_CC);
}
/* }}} */
@@ -2010,7 +2015,7 @@
{
php_info_print_table_start();
php_info_print_table_header(2, "Simplexml support", "enabled");
- php_info_print_table_row(2, "Revision", "$Revision: 1.174 $");
+ php_info_print_table_row(2, "Revision", "$Revision: 1.175 $");
php_info_print_table_row(2, "Schema support",
#ifdef LIBXML_SCHEMAS_ENABLED
"enabled");
http://cvs.php.net/diff.php/php-src/ext/simplexml/tests/025.phpt?r1=1.3&r2=1.4&ty=u
Index: php-src/ext/simplexml/tests/025.phpt
diff -u php-src/ext/simplexml/tests/025.phpt:1.3
php-src/ext/simplexml/tests/025.phpt:1.4
--- php-src/ext/simplexml/tests/025.phpt:1.3 Tue Nov 1 06:55:13 2005
+++ php-src/ext/simplexml/tests/025.phpt Tue Nov 1 18:21:29 2005
@@ -8,7 +8,7 @@
$xml =<<<EOF
<?xml version='1.0'?>
<xhtml:html xmlns:html='http://www.w3.org/1999/xhtml'
xmlns:xhtml='http://www.w3.org/TR/REC-html40'>
-<xhtml:head><xhtml:title>bla</xhtml:title></xhtml:head>
+<xhtml:head><xhtml:title
xmlns:xhtml='http://www.w3.org/TR/REC-html401'>bla</xhtml:title></xhtml:head>
<xhtml:body html:title="b">
<html:h1>bla</html:h1>
<foo:bar xmlns:foo='foobar' xmlns:baz='foobarbaz'/>
@@ -25,7 +25,9 @@
$xml =<<<EOF
<?xml version='1.0'?>
-<html xmlns='http://www.w3.org/1999/xhtml'/>
+<html xmlns='http://www.w3.org/1999/xhtml'>
+<head><title xmlns='http://www.w3.org/TR/REC-html40'>bla</title></head>
+</html>
EOF;
$sxe = simplexml_load_string($xml);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php