From 1b6c6da85d7fd268825e09cc8ff339540c1f77bc Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Sat, 27 Aug 2016 08:35:02 +0000 Subject: Issue #27506: Support bytes/bytearray.translate() delete as keyword argument Patch by Xiang Zhang. --- Objects/bytearrayobject.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'Objects/bytearrayobject.c') diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index de2dca95ec..b6631f9ac5 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1175,21 +1175,19 @@ bytearray.translate table: object Translation table, which must be a bytes object of length 256. - [ - deletechars: object - ] / + delete as deletechars: object(c_default="NULL") = b'' Return a copy with each character mapped by the given translation table. -All characters occurring in the optional argument deletechars are removed. +All characters occurring in the optional argument delete are removed. The remaining characters are mapped through the given translation table. [clinic start generated code]*/ static PyObject * bytearray_translate_impl(PyByteArrayObject *self, PyObject *table, - int group_right_1, PyObject *deletechars) -/*[clinic end generated code: output=2bebc86a9a1ff083 input=846a01671bccc1c5]*/ + PyObject *deletechars) +/*[clinic end generated code: output=b6a8f01c2a74e446 input=cfff956d4d127a9b]*/ { char *input, *output; const char *table_chars; @@ -1258,8 +1256,7 @@ bytearray_translate_impl(PyByteArrayObject *self, PyObject *table, for (i = inlen; --i >= 0; ) { c = Py_CHARMASK(*input++); if (trans_table[c] != -1) - if (Py_CHARMASK(*output++ = (char)trans_table[c]) == c) - continue; + *output++ = (char)trans_table[c]; } /* Fix the size of the resulting string */ if (inlen > 0) -- cgit v1.2.1