Skip to content

Commit fcbf282

Browse files
Removed PyMem_malloc & strncpy function call for speed boost
1 parent 7741925 commit fcbf282

1 file changed

Lines changed: 1 addition & 8 deletions

File tree

‎Objects/bytearrayobject.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,18 +2469,11 @@ bytearray_strip_impl_helper(PyByteArrayObject* self, PyObject* bytes, int stript
24692469
right++;
24702470
}
24712471

2472-
char *temp_ptr = PyMem_Malloc(mysize+1);
24732472

2474-
if(temp_ptr == NULL) {
2475-
return PyErr_NoMemory();
2476-
}
2477-
2478-
strncpy(temp_ptr,myptr, mysize);
2473+
PyObject *res = PyByteArray_FromStringAndSize(myptr + left, right - left);
24792474

24802475
if (bytes != Py_None)
24812476
PyBuffer_Release(&vbytes);
2482-
PyObject *res = PyByteArray_FromStringAndSize(temp_ptr + left, right - left);
2483-
PyMem_Free(temp_ptr);
24842477
return res;
24852478
}
24862479

0 commit comments

Comments
 (0)