Skip to content

Commit f1ddb09

Browse files
committed
chore: using more light operation instead of heavy operation
1 parent 70507f0 commit f1ddb09

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Objects/bytearrayobject.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,19 @@ static PyObject *
9898
_bytearray_with_buffer(PyByteArrayObject *self, PyObject *sub,
9999
Py_ssize_t start, Py_ssize_t end, _ba_bytes_op op)
100100
{
101-
Py_buffer view;
102101
PyObject *res;
103-
if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_SIMPLE) != 0) {
104-
return NULL;
105-
}
106-
res = op((const char *)view.buf, view.len, sub, start, end);
107-
PyBuffer_Release(&view);
102+
103+
Py_BEGIN_CRITICAL_SECTION(self);
104+
self->ob_exports++;
105+
Py_END_CRITICAL_SECTION();
106+
107+
res = op(PyByteArray_AS_STRING(self), Py_SIZE(self), sub, start, end);
108+
109+
Py_BEGIN_CRITICAL_SECTION(self);
110+
self->ob_exports--;
111+
assert(self->ob_exports >= 0);
112+
Py_END_CRITICAL_SECTION();
113+
108114
return res;
109115
}
110116

0 commit comments

Comments
 (0)