Skip to content
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: using more light operation instead of heavy operation
  • Loading branch information
fatelei committed Dec 12, 2025
commit 2df5acb86982e9683a82af7ce3e4c958c130ee10
18 changes: 12 additions & 6 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,19 @@ static PyObject *
_bytearray_with_buffer(PyByteArrayObject *self, PyObject *sub,
Py_ssize_t start, Py_ssize_t end, _ba_bytes_op op)
{
Py_buffer view;
PyObject *res;
if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_SIMPLE) != 0) {
return NULL;
}
res = op((const char *)view.buf, view.len, sub, start, end);
PyBuffer_Release(&view);

Py_BEGIN_CRITICAL_SECTION(self);
self->ob_exports++;
Py_END_CRITICAL_SECTION();

res = op(PyByteArray_AS_STRING(self), Py_SIZE(self), sub, start, end);

Py_BEGIN_CRITICAL_SECTION(self);
self->ob_exports--;
assert(self->ob_exports >= 0);
Py_END_CRITICAL_SECTION();

return res;
}

Expand Down
Loading