ZF-2999: performance optimization
Description
1.
isset(self::$_localeData[$locale])
// instead of
array_key_exists($locale, self::$_localeData)
2.
if ( isset(self::$_localeData[$locale]) && ($locale == 'root' || self::$_localeData[$locale] === false) ) {
// ....
}
// instead of
if (($locale == "auto") or ($locale == "root") or
($locale == "environment") or ($locale == "browser")) {
// ...
}
// -> OK this isn't for performance but for flexibly
- cache return value of getBrowser and if the environment variable must changable add an argument e.g. $reparse=false
Comments
Posted by Wil Sinclair (wil) on 2008-03-31T14:55:04.000+0000
Could you please evaluate and categorize as necessary.
Posted by Thomas Weidner (thomas) on 2008-05-26T13:04:51.000+0000
has been integrated with r9534 within the I18N core, not only Zend_Locale.
brakes existing functionality as it disallows locales like "en_DE" and therefor brakes the downgrading
is not necessary as the locale itself is cached, so the browser response has not to be cached alone.
Posted by Marc Bennewitz (GIATA mbH) (mben) on 2008-05-27T04:13:20.000+0000
Hi Thomas
Regarding my last statement: it is very slow to parse the result of "$locale->getBrowser()" on every method call, because the clients browser will not change in one connection, but the environment value of "HTTP_ACCEPT_LANGUAGE" can change in one connection during script execution. To get the array of user accepted locales is not the same as to create a browser locale "new Zend_Locale('browser')". Furthermore the method getBrowser will be called by getDefault() and the method getDefault() will be called by setLocale()
Posted by Thomas Weidner (thomas) on 2008-05-27T10:19:54.000+0000
Locale is locale, independently from the creation. The locale can change within the same session.
Also if you need the browsers locale you would not parse it again and again. You would normally store it within your session to reuse it.
Only if you accept that the locale can change within the same session you would parse the locale once more. And when you use setLocale the browser will only then be parsed when you give one of the autolocales or define that you want to retrieve the autolocale.
In my opinion there is still no benefit of having another option added.
Posted by Marc Bennewitz (GIATA mbH) (mben) on 2008-05-28T01:03:58.000+0000
Hi Thomas
this is a little test script which displays all calls of the getBrowser-method and its output:
Zend_Locale:
testscript:
output:
Posted by Wil Sinclair (wil) on 2008-09-02T10:39:00.000+0000
Updating for the 1.6.0 release.