Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f561634

Browse files
committed
Use _PyObject_CallMethodIdObjArgs() in _elementtree
Issue #28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() when the format string was only made of "O" formats, PyObject* arguments. _PyObject_CallMethodIdObjArgs() avoids the creation of a temporary tuple and doesn't have to parse a format string.
1 parent 5670764 commit f561634

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

Modules/_elementtree.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,8 @@ _elementtree_Element_find_impl(ElementObject *self, PyObject *path,
11711171

11721172
if (checkpath(path) || namespaces != Py_None) {
11731173
_Py_IDENTIFIER(find);
1174-
return _PyObject_CallMethodId(
1175-
st->elementpath_obj, &PyId_find, "OOO", self, path, namespaces
1174+
return _PyObject_CallMethodIdObjArgs(
1175+
st->elementpath_obj, &PyId_find, self, path, namespaces, NULL
11761176
);
11771177
}
11781178

@@ -1216,8 +1216,9 @@ _elementtree_Element_findtext_impl(ElementObject *self, PyObject *path,
12161216
elementtreestate *st = ET_STATE_GLOBAL;
12171217

12181218
if (checkpath(path) || namespaces != Py_None)
1219-
return _PyObject_CallMethodId(
1220-
st->elementpath_obj, &PyId_findtext, "OOOO", self, path, default_value, namespaces
1219+
return _PyObject_CallMethodIdObjArgs(
1220+
st->elementpath_obj, &PyId_findtext,
1221+
self, path, default_value, namespaces, NULL
12211222
);
12221223

12231224
if (!self->extra) {
@@ -1271,8 +1272,8 @@ _elementtree_Element_findall_impl(ElementObject *self, PyObject *path,
12711272

12721273
if (checkpath(tag) || namespaces != Py_None) {
12731274
_Py_IDENTIFIER(findall);
1274-
return _PyObject_CallMethodId(
1275-
st->elementpath_obj, &PyId_findall, "OOO", self, tag, namespaces
1275+
return _PyObject_CallMethodIdObjArgs(
1276+
st->elementpath_obj, &PyId_findall, self, tag, namespaces, NULL
12761277
);
12771278
}
12781279

@@ -1318,8 +1319,8 @@ _elementtree_Element_iterfind_impl(ElementObject *self, PyObject *path,
13181319
_Py_IDENTIFIER(iterfind);
13191320
elementtreestate *st = ET_STATE_GLOBAL;
13201321

1321-
return _PyObject_CallMethodId(
1322-
st->elementpath_obj, &PyId_iterfind, "OOO", self, tag, namespaces);
1322+
return _PyObject_CallMethodIdObjArgs(
1323+
st->elementpath_obj, &PyId_iterfind, self, tag, namespaces, NULL);
13231324
}
13241325

13251326
/*[clinic input]
@@ -2440,7 +2441,7 @@ treebuilder_add_subelement(PyObject *element, PyObject *child)
24402441
}
24412442
else {
24422443
PyObject *res;
2443-
res = _PyObject_CallMethodId(element, &PyId_append, "O", child);
2444+
res = _PyObject_CallMethodIdObjArgs(element, &PyId_append, child, NULL);
24442445
if (res == NULL)
24452446
return -1;
24462447
Py_DECREF(res);

0 commit comments

Comments
 (0)