Hygiene: Use strtr() instead of str_replace() for character swapping
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 6 Jul 2015 09:17:47 +0000 (10:17 +0100)
committerKrinkle <krinklemail@gmail.com>
Mon, 6 Jul 2015 20:25:19 +0000 (20:25 +0000)
commitc318e3a265f28043038115ad4e027d2dc7a6c030
tree508dd4637e8197729bafc483ecdac15858bc4967
parent0bdcf342fc26fcd66cf1b19884ca25cdaf857899
Hygiene: Use strtr() instead of str_replace() for character swapping

strtr() is marginally faster as it runs through the string only
once. A better fit for one-for-one character translation.

The strtr() function also supports an associative array as second
parameter for entire string replacements. This, too, has the same
performance and predictable behaviour (starts with the longest key).
Whereas str_replace is for more aggressive needs where you want
multiple passes until there are no further matches.

The associative array form is arguably also easier to understand
and harder to mess up since the needle/replacement pairs are
explicitly connected instead of two separate arrays.

Also:
* Use getFormattedNsText instead of strtr( getNsText, .. ) which
  reduces duplication of this fact through a more semantic intent.

Change-Id: Ie23e4210a5b6908dd79eebc8a2b931d12fe31af6
includes/Export.php
includes/GlobalFunctions.php
includes/Linker.php
includes/Title.php
includes/api/ApiQueryAllUsers.php
includes/cache/LinkBatch.php
includes/filerepo/LocalRepo.php
includes/resourceloader/ResourceLoaderModule.php
languages/Language.php