https://hg.python.org/cpython/rev/1fe904420c20 changeset: 99519:1fe904420c20 parent: 99517:5176e8a2e258 user: Serhiy Storchaka <storchaka at gmail.com> date: Thu Dec 10 09:51:53 2015 +0200 summary: Issue #25638: Optimized ElementTree parsing; it is now 10% faster. files: Misc/NEWS | 1 + Modules/_elementtree.c | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -110,6 +110,7 @@ ------- - 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. diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -2491,10 +2491,17 @@ self->data = NULL; } - if (self->element_factory && self->element_factory != Py_None) { + 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); - } else { - node = create_new_element(tag, attrib); + Py_DECREF(attrib); + } + else { + node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib); } if (!node) { return NULL; @@ -2959,12 +2966,8 @@ 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 @@ 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; -- Repository URL: https://hg.python.org/cpython
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4