ZF-9795: Zend_Locale::isLocale() is called often, deserves local cache

Description

Zend_Locale::isLocale() is called a lot (up to several hundred times) in a locale-aware applications, especially in multi-language applications.

Since in most cases it is being called with 1-2 values - it is possible to save some execution time by storing result of its work into local static variable and use it to return result immediately on subsequent calls with same arguments.

Comments

Integrated with r22177

Note: Only when you use tokens which are recognised by Zend_Locale, like "en_US" the improvement will take place. In all other cases, where complete detection has to be done, the old behaviour will be used because the order could be changed in the detection rules also afterwards.

This is no neg as all locale aware classes automatically correct locale strings to those tokens and use them for further processing.

Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in /*/library/Zend/Locale.php on line 811


        if (($locale instanceof Zend_Locale)
            || (is_array($locale) && array_key_exists($locale, self::$_localeData))
        ) {
            return true;
        }

Isn't the following kind of strange, as array_key_exists expects a string or an integer instead of an array

is_array($locale) && array_key_exists($locale, self::$_localeData)