Commit 36ff9979 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #25638: Optimized ElementTree parsing; it is now 10% faster.

parent 956244be
...@@ -110,6 +110,7 @@ Library ...@@ -110,6 +110,7 @@ Library
------- -------
- Issue #25638: Optimized ElementTree.iterparse(); it is now 2x faster. - Issue #25638: Optimized ElementTree.iterparse(); it is now 2x faster.
Optimized ElementTree parsing; it is now 10% faster.
- Issue #25761: Improved detecting errors in broken pickle data. - Issue #25761: Improved detecting errors in broken pickle data.
......
...@@ -2491,10 +2491,17 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag, ...@@ -2491,10 +2491,17 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
self->data = NULL; self->data = NULL;
} }
if (self->element_factory && self->element_factory != Py_None) { if (!self->element_factory || self->element_factory == Py_None) {
node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
} else {
node = create_new_element(tag, attrib); 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) { if (!node) {
return NULL; return NULL;
...@@ -2959,12 +2966,8 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2959,12 +2966,8 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
attrib_in += 2; attrib_in += 2;
} }
} else { } else {
/* Pass an empty dictionary on */ Py_INCREF(Py_None);
attrib = PyDict_New(); attrib = Py_None;
if (!attrib) {
Py_DECREF(tag);
return;
}
} }
if (TreeBuilder_CheckExact(self->target)) { if (TreeBuilder_CheckExact(self->target)) {
...@@ -2973,6 +2976,14 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2973,6 +2976,14 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
tag, attrib); tag, attrib);
} }
else if (self->handle_start) { 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); res = PyObject_CallFunction(self->handle_start, "OO", tag, attrib);
} else } else
res = NULL; res = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment