mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
GH-100117: Make co_lines
more efficient (GH-100447)
This commit is contained in:
parent
b2f7b2ef0b
commit
f07daaf4f7
4 changed files with 26 additions and 38 deletions
|
@ -1183,6 +1183,14 @@ lineiter_dealloc(lineiterator *li)
|
|||
Py_TYPE(li)->tp_free(li);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_source_offset_converter(int *value) {
|
||||
if (*value == -1) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return PyLong_FromLong(*value);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
lineiter_next(lineiterator *li)
|
||||
{
|
||||
|
@ -1190,31 +1198,17 @@ lineiter_next(lineiterator *li)
|
|||
if (!_PyLineTable_NextAddressRange(bounds)) {
|
||||
return NULL;
|
||||
}
|
||||
PyObject *start = NULL;
|
||||
PyObject *end = NULL;
|
||||
PyObject *line = NULL;
|
||||
PyObject *result = PyTuple_New(3);
|
||||
start = PyLong_FromLong(bounds->ar_start);
|
||||
end = PyLong_FromLong(bounds->ar_end);
|
||||
if (bounds->ar_line < 0) {
|
||||
line = Py_NewRef(Py_None);
|
||||
int start = bounds->ar_start;
|
||||
int line = bounds->ar_line;
|
||||
// Merge overlapping entries:
|
||||
while (_PyLineTable_NextAddressRange(bounds)) {
|
||||
if (bounds->ar_line != line) {
|
||||
_PyLineTable_PreviousAddressRange(bounds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
line = PyLong_FromLong(bounds->ar_line);
|
||||
}
|
||||
if (result == NULL || start == NULL || end == NULL || line == NULL) {
|
||||
goto error;
|
||||
}
|
||||
PyTuple_SET_ITEM(result, 0, start);
|
||||
PyTuple_SET_ITEM(result, 1, end);
|
||||
PyTuple_SET_ITEM(result, 2, line);
|
||||
return result;
|
||||
error:
|
||||
Py_XDECREF(start);
|
||||
Py_XDECREF(end);
|
||||
Py_XDECREF(line);
|
||||
Py_XDECREF(result);
|
||||
return result;
|
||||
return Py_BuildValue("iiO&", start, bounds->ar_end,
|
||||
_source_offset_converter, &line);
|
||||
}
|
||||
|
||||
PyTypeObject _PyLineIterator = {
|
||||
|
@ -1290,14 +1284,6 @@ positionsiter_dealloc(positionsiterator* pi)
|
|||
Py_TYPE(pi)->tp_free(pi);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
_source_offset_converter(int* value) {
|
||||
if (*value == -1) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return PyLong_FromLong(*value);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
positionsiter_next(positionsiterator* pi)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue