Skip to content

Commit 593bb30

Browse files
sir-sigurdbenjaminp
authored andcommitted
closes bpo-34599: Improve performance of _Py_bytes_capitalize(). (GH-9083)
1 parent b03c2c5 commit 593bb30

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

Objects/bytes_methods.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -361,23 +361,9 @@ and the rest lower-cased.");
361361
void
362362
_Py_bytes_capitalize(char *result, const char *s, Py_ssize_t len)
363363
{
364-
Py_ssize_t i;
365-
366-
if (0 < len) {
367-
int c = Py_CHARMASK(*s++);
368-
if (Py_ISLOWER(c))
369-
*result = Py_TOUPPER(c);
370-
else
371-
*result = c;
372-
result++;
373-
}
374-
for (i = 1; i < len; i++) {
375-
int c = Py_CHARMASK(*s++);
376-
if (Py_ISUPPER(c))
377-
*result = Py_TOLOWER(c);
378-
else
379-
*result = c;
380-
result++;
364+
if (len > 0) {
365+
*result = Py_TOUPPER(*s);
366+
_Py_bytes_lower(result + 1, s + 1, len - 1);
381367
}
382368
}
383369

0 commit comments

Comments
 (0)