4612c07daf3859e6ebfc408dc0ef9aed5f97f166 |
|
05-Apr-2011 |
Luke Smith <lsmith@yahoo-inc.com> |
Break out common special chars from fn replace.
Per suggestion from Brian Kaull, the performance of
string.replace(regex, fn) is far slower than
string.replace(regex, string), so for common special
chars, such as \ \n " etc, preprocess strings with
specific regexes targeting these characters, using the
replace(regex, string) signature. Then process the string
with the generic replace(regex, fn) for other special
characters. So, more calls to replace are made, but
very few should trigger replacement from the generic
replace(regex, fn).
Additionally, add adaptive caching of special chars
to their targeting regex if that char commonly appears
in strings. Base the cache threshold on new
Y.JSON.charCacheThreshold config. |