]> granicus.if.org Git - php/commitdiff
Merge from 5.2:
authorStanislav Malyshev <stas@php.net>
Tue, 5 Dec 2006 02:55:27 +0000 (02:55 +0000)
committerStanislav Malyshev <stas@php.net>
Tue, 5 Dec 2006 02:55:27 +0000 (02:55 +0000)
Improve tolower()-related functions on Windows and VC2005 by caching locale and using
tolower_l function.

Zend/zend_operators.c
Zend/zend_operators.h
ext/standard/basic_functions.c
ext/standard/string.c
main/main.c

index ca9cac948cb0b8f959726cdb209b356648a3c2d4..8f49df7c01827e3cdbdd7a33f18b4caa887960bb 100644 (file)
 
 #define LONG_SIGN_MASK (1L << (8*sizeof(long)-1))
 
+#if ZEND_USE_TOLOWER_L
+#include <locale.h>
+static _locale_t current_locale = NULL;
+/* this is true global! may lead to strange effects on ZTS, but so may setlocale() */
+#define zend_tolower(c) _tolower_l(c, current_locale)
+#else
+#define zend_tolower(c) tolower(c)
+#endif
+
 ZEND_API int zend_atoi(const char *str, int str_len)
 {
        int retval;
@@ -2331,6 +2340,13 @@ ZEND_API int zval_is_true(zval *op)
        return (Z_LVAL_P(op) ? 1 : 0);
 }
 
+#ifdef ZEND_USE_TOLOWER_L
+ZEND_API void zend_update_current_locale()
+{
+        current_locale = _get_current_locale();
+}
+#endif
+
 ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned int length)
 {
        register unsigned char *str = (unsigned char*)source;
@@ -2338,7 +2354,7 @@ ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned in
        register unsigned char *end = str + length;
 
        while (str < end) {
-               *result++ = tolower((int)*str++);
+               *result++ = zend_tolower((int)*str++);
        }
        *result = '\0';
 
@@ -2390,7 +2406,7 @@ ZEND_API void zend_str_tolower(char *str, unsigned int length)
        register unsigned char *end = p + length;
 
        while (p < end) {
-               *p = tolower((int)*p);
+               *p = zend_tolower((int)*p);
                p++;
        }
 }
@@ -2503,8 +2519,8 @@ ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2)
        len = MIN(len1, len2);
 
        while (len--) {
-               c1 = tolower((int)*(unsigned char *)s1++);
-               c2 = tolower((int)*(unsigned char *)s2++);
+               c1 = zend_tolower((int)*(unsigned char *)s1++);
+               c2 = zend_tolower((int)*(unsigned char *)s2++);
                if (c1 != c2) {
                        return c1 - c2;
                }
@@ -2530,8 +2546,8 @@ ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, u
        len = MIN(length, MIN(len1, len2));
 
        while (len--) {
-               c1 = tolower((int)*(unsigned char *)s1++);
-               c2 = tolower((int)*(unsigned char *)s2++);
+               c1 = zend_tolower((int)*(unsigned char *)s1++);
+               c2 = zend_tolower((int)*(unsigned char *)s2++);
                if (c1 != c2) {
                        return c1 - c2;
                }
index e5dc13c4ab56a698fc699210ead8014009614c2b..ec826b6059ffe45ce638924fef8409ac01fe807f 100644 (file)
@@ -451,6 +451,19 @@ END_EXTERN_C()
 #define Z_TYPE_P(zval_p)       Z_TYPE(*zval_p)
 #define Z_TYPE_PP(zval_pp)     Z_TYPE(**zval_pp)
 
+#if HAVE_SETLOCALE && defined(ZEND_WIN32) && !defined(ZTS) && defined(_MSC_VER) && (_MSC_VER >= 1400)
+/* This is performance improvement of tolower() on Windows and VC2005
+ * Gives 10-18% on bench.php
+ */
+#define ZEND_USE_TOLOWER_L 1
+#endif
+
+#ifdef ZEND_USE_TOLOWER_L
+ZEND_API void zend_update_current_locale();
+#else
+#define zend_update_current_locale()
+#endif
+
 #endif
 
 /*
index e295b165ca1bd73a9a82ac71218b8af77e59f45a..2891d0e457316d8036f19813df3949cbe962359f 100644 (file)
@@ -4164,6 +4164,7 @@ PHP_RSHUTDOWN_FUNCTION(basic)
        if (BG(locale_string) != NULL) {
                setlocale(LC_ALL, "C");
                setlocale(LC_CTYPE, "");
+               zend_update_current_locale();
        }
        STR_FREE(BG(locale_string));
        BG(locale_string) = NULL;
index ab173a39e71e807fe9607f3a56f4947fc374c8c3..ab610e0a79d15bc265d1e34a85d63da58be8e1f8 100644 (file)
@@ -6083,6 +6083,7 @@ PHP_FUNCTION(setlocale)
                }
 
                retval = setlocale (cat, loc);
+               zend_update_current_locale();
                if (retval) {
                        /* Remember if locale was changed */
                        if (loc) {
index 0653415069e33a0c01977b744c7f820d47c2217e..fc9984c51941e5e7c5a45f8280d0079e69ba7c39 100644 (file)
@@ -1620,6 +1620,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
 
 #if HAVE_SETLOCALE
        setlocale(LC_CTYPE, "");
+       zend_update_current_locale();
 #endif
 
 #if HAVE_TZSET