File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -356,26 +356,24 @@ The bytes objects frm and to must be of the same length.");
356
356
PyObject *
357
357
_Py_bytes_maketrans (Py_buffer * frm , Py_buffer * to )
358
358
{
359
- PyObject * res = NULL ;
360
- Py_ssize_t i ;
361
- char * p ;
362
-
363
359
if (frm -> len != to -> len ) {
364
360
PyErr_Format (PyExc_ValueError ,
365
361
"maketrans arguments must have same length" );
366
362
return NULL ;
367
363
}
368
- res = PyBytes_FromStringAndSize ( NULL , 256 );
369
- if (!res )
364
+ PyBytesWriter * writer = PyBytesWriter_Create ( 256 );
365
+ if (!writer ) {
370
366
return NULL ;
371
- p = PyBytes_AS_STRING (res );
367
+ }
368
+ char * p = PyBytesWriter_GetData (writer );
369
+ Py_ssize_t i ;
372
370
for (i = 0 ; i < 256 ; i ++ )
373
371
p [i ] = (char ) i ;
374
372
for (i = 0 ; i < frm -> len ; i ++ ) {
375
373
p [((unsigned char * )frm -> buf )[i ]] = ((char * )to -> buf )[i ];
376
374
}
377
375
378
- return res ;
376
+ return PyBytesWriter_Finish ( writer ) ;
379
377
}
380
378
381
379
#define FASTSEARCH fastsearch
You can’t perform that action at this time.
0 commit comments