FormatJson: microoptimizations for UTF8_OK mode
authorKevin Israel <pleasestand@live.com>
Fri, 5 Apr 2013 19:15:02 +0000 (15:15 -0400)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 8 Apr 2013 05:07:07 +0000 (05:07 +0000)
commite9443cf677bf841eedb6b599f54aa526779035db
tree07824754d0a3f3caf2efb58dbac3f465fe5bb390
parent54811d33fee926a6ed486708ce5d12eef20b092d
FormatJson: microoptimizations for UTF8_OK mode

* Replace strtr with str_replace where faster.
* Use addcslashes to escape json_encode's output. Because no control
  characters are included, the only characters that have to be
  escaped are \ and ". (irrelevant for PHP 5.4+ installations)

Re-encoding a ~1.5 MB API response from the Chinese Wikipedia:
* PHP 5.3: 32% faster (from 347 ms to 239 ms)
* PHP 5.4: 70% faster (from 51 ms to 15 ms)
* HHVM: 42% faster (from 326 ms to 191 ms)

Change-Id: I7c9342682986d40a2f2436ac978390b6018a3521
includes/json/FormatJson.php