Improve the performance of backslashit() by avoiding regular expressions. backslashit() is used heavily in date_i18n().

props jbutkus.
fixes #22286.



git-svn-id: https://develop.svn.wordpress.org/trunk@24051 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2013-04-22 20:01:57 +00:00
parent bd7837e30e
commit 2958875d6c

View File

@ -1369,9 +1369,9 @@ function zeroise($number, $threshold) {
* @return string String with backslashes inserted. * @return string String with backslashes inserted.
*/ */
function backslashit($string) { function backslashit($string) {
$string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string); if ( isset( $string[0] ) && $string[0] >= '0' && $string[0] <= '9' )
$string = preg_replace('/([a-z])/i', '\\\\\1', $string); $string = '\\\\' . $string;
return $string; return addcslashes( $string, 'A..Za..z' );
} }
/** /**