summaryrefslogtreecommitdiffstats
path: root/Modules/_elementtree.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-12-10 07:51:53 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-12-10 07:51:53 (GMT)
commit36ff997988bdf2a72f362e60b7b03f439506411c (patch)
tree4bf6217c094b7ff47d3a38d4e3e2847d6ba6238c /Modules/_elementtree.c
parent956244bee1f97a0a86de2c33d803f49db2214450 (diff)
downloadcpython-36ff997988bdf2a72f362e60b7b03f439506411c.zip
cpython-36ff997988bdf2a72f362e60b7b03f439506411c.tar.gz
cpython-36ff997988bdf2a72f362e60b7b03f439506411c.tar.bz2
Issue #25638: Optimized ElementTree parsing; it is now 10% faster.
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r--Modules/_elementtree.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 3cf3d59..c483d87 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2491,10 +2491,17 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
self->data = NULL;
}
- if (self->element_factory && self->element_factory != Py_None) {
- node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
- } else {
+ if (!self->element_factory || self->element_factory == Py_None) {
node = create_new_element(tag, attrib);
+ } else if (attrib == Py_None) {
+ attrib = PyDict_New();
+ if (!attrib)
+ return NULL;
+ node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
+ Py_DECREF(attrib);
+ }
+ else {
+ node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
}
if (!node) {
return NULL;
@@ -2959,12 +2966,8 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
attrib_in += 2;
}
} else {
- /* Pass an empty dictionary on */
- attrib = PyDict_New();
- if (!attrib) {
- Py_DECREF(tag);
- return;
- }
+ Py_INCREF(Py_None);
+ attrib = Py_None;
}
if (TreeBuilder_CheckExact(self->target)) {
@@ -2973,6 +2976,14 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
tag, attrib);
}
else if (self->handle_start) {
+ if (attrib == Py_None) {
+ Py_DECREF(attrib);
+ attrib = PyDict_New();
+ if (!attrib) {
+ Py_DECREF(tag);
+ return;
+ }
+ }
res = PyObject_CallFunction(self->handle_start, "OO", tag, attrib);
} else
res = NULL;