@@ -90,6 +90,24 @@ bytearray_releasebuffer(PyObject *self, Py_buffer *view)
9090 Py_END_CRITICAL_SECTION ();
9191}
9292
93+ typedef PyObject * (* _ba_bytes_op )(const char * buf , Py_ssize_t len ,
94+ PyObject * sub , Py_ssize_t start ,
95+ Py_ssize_t end );
96+
97+ static PyObject *
98+ _bytearray_with_buffer (PyByteArrayObject * self , PyObject * sub ,
99+ Py_ssize_t start , Py_ssize_t end , _ba_bytes_op op )
100+ {
101+ Py_buffer view ;
102+ 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 );
108+ return res ;
109+ }
110+
93111static int
94112_canresize (PyByteArrayObject * self )
95113{
@@ -1243,24 +1261,6 @@ Return the lowest index in B where subsection 'sub' is found, such that 'sub' is
12431261Return -1 on failure.
12441262[clinic start generated code]*/
12451263
1246- typedef PyObject * (* _ba_bytes_op )(const char * buf , Py_ssize_t len ,
1247- PyObject * sub , Py_ssize_t start ,
1248- Py_ssize_t end );
1249-
1250- static PyObject *
1251- _bytearray_with_buffer (PyByteArrayObject * self , PyObject * sub ,
1252- Py_ssize_t start , Py_ssize_t end , _ba_bytes_op op )
1253- {
1254- Py_buffer view ;
1255- PyObject * res ;
1256- if (PyObject_GetBuffer ((PyObject * )self , & view , PyBUF_SIMPLE ) != 0 ) {
1257- return NULL ;
1258- }
1259- res = op ((const char * )view .buf , view .len , sub , start , end );
1260- PyBuffer_Release (& view );
1261- return res ;
1262- }
1263-
12641264static PyObject *
12651265bytearray_find_impl (PyByteArrayObject * self , PyObject * sub , Py_ssize_t start ,
12661266 Py_ssize_t end )
0 commit comments