diff options
author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2018-09-07 04:54:49 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2018-09-07 04:54:49 (GMT) |
commit | 593bb30e82eded7f2ec02f7d1aa49742e6962113 (patch) | |
tree | 32070fed67d41dde884b296e2a21c59ec1cfcaf1 /Objects/bytes_methods.c | |
parent | b03c2c51909e3b5b5966d86a2829b5ddf2d496aa (diff) | |
download | cpython-593bb30e82eded7f2ec02f7d1aa49742e6962113.zip cpython-593bb30e82eded7f2ec02f7d1aa49742e6962113.tar.gz cpython-593bb30e82eded7f2ec02f7d1aa49742e6962113.tar.bz2 |
closes bpo-34599: Improve performance of _Py_bytes_capitalize(). (GH-9083)
Diffstat (limited to 'Objects/bytes_methods.c')
-rw-r--r-- | Objects/bytes_methods.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/Objects/bytes_methods.c b/Objects/bytes_methods.c index 05679e3..37c5f7d 100644 --- a/Objects/bytes_methods.c +++ b/Objects/bytes_methods.c @@ -361,23 +361,9 @@ and the rest lower-cased."); void _Py_bytes_capitalize(char *result, const char *s, Py_ssize_t len) { - Py_ssize_t i; - - if (0 < len) { - int c = Py_CHARMASK(*s++); - if (Py_ISLOWER(c)) - *result = Py_TOUPPER(c); - else - *result = c; - result++; - } - for (i = 1; i < len; i++) { - int c = Py_CHARMASK(*s++); - if (Py_ISUPPER(c)) - *result = Py_TOLOWER(c); - else - *result = c; - result++; + if (len > 0) { + *result = Py_TOUPPER(*s); + _Py_bytes_lower(result + 1, s + 1, len - 1); } } |