]> granicus.if.org Git - php/commitdiff
Optimize php_unicode_is_lower/upper for ASCII
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 20 Jul 2017 09:48:52 +0000 (11:48 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 20 Jul 2017 11:58:40 +0000 (13:58 +0200)
ext/mbstring/php_unicode.h

index 3a6c75ce86da2ca0d014f9feaebd590a064aa61c..61415216c0618ccd5924c9a4aab979922b120d81 100644 (file)
@@ -103,6 +103,24 @@ MBSTRING_API char *php_unicode_convert_case(
 #define PHP_UNICODE_CASE_LOWER 1
 #define PHP_UNICODE_CASE_TITLE 2
 
+/* Optimize the common ASCII case for lower/upper */
+
+static inline int php_unicode_is_lower(unsigned long code) {
+       if (code < 0x80) {
+               return code >= 0x61 && code <= 0x7A;
+       } else {
+               return php_unicode_is_prop1(code, UC_LL);
+       }
+}
+
+static inline int php_unicode_is_upper(unsigned long code) {
+       if (code < 0x80) {
+               return code >= 0x41 && code <= 0x5A;
+       } else {
+               return php_unicode_is_prop1(code, UC_LU);
+       }
+}
+
 #define php_unicode_is_alpha(cc) php_unicode_is_prop(cc, UC_LU, UC_LL, UC_LM, UC_LO, UC_LT, -1)
 #define php_unicode_is_digit(cc) php_unicode_is_prop1(cc, UC_ND)
 #define php_unicode_is_alnum(cc) php_unicode_is_prop(cc, UC_LU, UC_LL, UC_LM, UC_LO, UC_LT, UC_ND, -1)
@@ -118,8 +136,6 @@ MBSTRING_API char *php_unicode_convert_case(
                                UC_LU, UC_LL, UC_LT, UC_LM, UC_LO, UC_PC, UC_PD, \
                                UC_PS, UC_PE, UC_PO, UC_SM, UC_SM, UC_SC, UC_SK, \
                                UC_SO, UC_ZS, UC_PI, UC_PF, -1)
-#define php_unicode_is_upper(cc) php_unicode_is_prop1(cc, UC_LU)
-#define php_unicode_is_lower(cc) php_unicode_is_prop1(cc, UC_LL)
 #define php_unicode_is_title(cc) php_unicode_is_prop1(cc, UC_LT)
 #define php_unicode_is_xdigit(cc) php_unicode_is_prop1(cc, UC_HD)