]> granicus.if.org Git - python/commitdiff
closes bpo-34599: Improve performance of _Py_bytes_capitalize(). (GH-9083)
authorSergey Fedoseev <fedoseev.sergey@gmail.com>
Fri, 7 Sep 2018 04:54:49 +0000 (09:54 +0500)
committerBenjamin Peterson <benjamin@python.org>
Fri, 7 Sep 2018 04:54:49 +0000 (21:54 -0700)
Objects/bytes_methods.c

index 05679e31c9d68ceb240922ddb1613ba79db3f29e..37c5f7dbc8040bec2f5bc0e1905254932541a593 100644 (file)
@@ -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);
     }
 }