gh-67565: Remove redundant C-contiguity checks (GH-105521)

Co-authored-by: Stefan Krah <skrah@bytereef.org>
This commit is contained in:
Furkan Onder 2023-10-23 12:54:46 +03:00 committed by GitHub
parent c84b0390c0
commit 32c37fe1ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 36 additions and 464 deletions

View file

@ -162,10 +162,6 @@ bytearray_removeprefix(PyByteArrayObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&prefix, 'C')) {
_PyArg_BadArgument("removeprefix", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = bytearray_removeprefix_impl(self, &prefix);
exit:
@ -202,10 +198,6 @@ bytearray_removesuffix(PyByteArrayObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&suffix, 'C')) {
_PyArg_BadArgument("removesuffix", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = bytearray_removesuffix_impl(self, &suffix);
exit:
@ -316,17 +308,9 @@ bytearray_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&frm, 'C')) {
_PyArg_BadArgument("maketrans", "argument 1", "contiguous buffer", args[0]);
goto exit;
}
if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&to, 'C')) {
_PyArg_BadArgument("maketrans", "argument 2", "contiguous buffer", args[1]);
goto exit;
}
return_value = bytearray_maketrans_impl(&frm, &to);
exit:
@ -376,17 +360,9 @@ bytearray_replace(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nar
if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&old, 'C')) {
_PyArg_BadArgument("replace", "argument 1", "contiguous buffer", args[0]);
goto exit;
}
if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&new, 'C')) {
_PyArg_BadArgument("replace", "argument 2", "contiguous buffer", args[1]);
goto exit;
}
if (nargs < 3) {
goto skip_optional;
}
@ -1285,4 +1261,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
{
return bytearray_sizeof_impl(self);
}
/*[clinic end generated code: output=fc2b9ccabe0e6782 input=a9049054013a1b77]*/
/*[clinic end generated code: output=0797a5e03cda2a16 input=a9049054013a1b77]*/

View file

@ -141,10 +141,6 @@ bytes_partition(PyBytesObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&sep, 'C')) {
_PyArg_BadArgument("partition", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = bytes_partition_impl(self, &sep);
exit:
@ -184,10 +180,6 @@ bytes_rpartition(PyBytesObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&sep, 'C')) {
_PyArg_BadArgument("rpartition", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = bytes_rpartition_impl(self, &sep);
exit:
@ -503,17 +495,9 @@ bytes_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&frm, 'C')) {
_PyArg_BadArgument("maketrans", "argument 1", "contiguous buffer", args[0]);
goto exit;
}
if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&to, 'C')) {
_PyArg_BadArgument("maketrans", "argument 2", "contiguous buffer", args[1]);
goto exit;
}
return_value = bytes_maketrans_impl(&frm, &to);
exit:
@ -563,17 +547,9 @@ bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&old, 'C')) {
_PyArg_BadArgument("replace", "argument 1", "contiguous buffer", args[0]);
goto exit;
}
if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&new, 'C')) {
_PyArg_BadArgument("replace", "argument 2", "contiguous buffer", args[1]);
goto exit;
}
if (nargs < 3) {
goto skip_optional;
}
@ -629,10 +605,6 @@ bytes_removeprefix(PyBytesObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&prefix, 'C')) {
_PyArg_BadArgument("removeprefix", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = bytes_removeprefix_impl(self, &prefix);
exit:
@ -669,10 +641,6 @@ bytes_removesuffix(PyBytesObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&suffix, 'C')) {
_PyArg_BadArgument("removesuffix", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = bytes_removesuffix_impl(self, &suffix);
exit:
@ -1061,4 +1029,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=da013a7e257f5c6e input=a9049054013a1b77]*/
/*[clinic end generated code: output=8a49dbbd78914a6f input=a9049054013a1b77]*/