Skip to content

Commit 94f6fa6

Browse files
committed
Issue python#13738: Simplify implementation of bytes.lower() and bytes.upper().
1 parent 69f39a5 commit 94f6fa6

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #13738: Simplify implementation of bytes.lower() and bytes.upper().
14+
1315
- Issue #13577: Built-in methods and functions now have a __qualname__.
1416
Patch by sbt.
1517

Objects/bytes_methods.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,8 @@ _Py_bytes_lower(char *result, const char *cptr, Py_ssize_t len)
248248
{
249249
Py_ssize_t i;
250250

251-
Py_MEMCPY(result, cptr, len);
252-
253251
for (i = 0; i < len; i++) {
254-
int c = Py_CHARMASK(result[i]);
255-
if (Py_ISUPPER(c))
256-
result[i] = Py_TOLOWER(c);
252+
result[i] = Py_TOLOWER((unsigned char) cptr[i]);
257253
}
258254
}
259255

@@ -268,12 +264,8 @@ _Py_bytes_upper(char *result, const char *cptr, Py_ssize_t len)
268264
{
269265
Py_ssize_t i;
270266

271-
Py_MEMCPY(result, cptr, len);
272-
273267
for (i = 0; i < len; i++) {
274-
int c = Py_CHARMASK(result[i]);
275-
if (Py_ISLOWER(c))
276-
result[i] = Py_TOUPPER(c);
268+
result[i] = Py_TOUPPER((unsigned char) cptr[i]);
277269
}
278270
}
279271

0 commit comments

Comments
 (0)