From 2958875d6c3dd4c68498684035bce82d4872b50b Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 22 Apr 2013 20:01:57 +0000 Subject: [PATCH] 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 --- wp-includes/formatting.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 7a7ef52bb1..fc1b1509e0 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -1369,9 +1369,9 @@ function zeroise($number, $threshold) { * @return string String with backslashes inserted. */ function backslashit($string) { - $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string); - $string = preg_replace('/([a-z])/i', '\\\\\1', $string); - return $string; + if ( isset( $string[0] ) && $string[0] >= '0' && $string[0] <= '9' ) + $string = '\\\\' . $string; + return addcslashes( $string, 'A..Za..z' ); } /**