Opened 10 years ago
Closed 9 years ago
#37643 closed enhancement (fixed)
Convert chr() function calls in remove_accents() to string literals for better performance.
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.7 | Priority: | normal |
| Severity: | normal | Version: | 1.5 |
| Component: | Formatting | Keywords: | has-patch |
| Focuses: | performance | Cc: |
Description
Changing the chr() function calls in remove_accents() to string literals gives a "for free" performance boost (twice as fast for PHP 5 and frice for PHP 7 based on rough tests), as well as being more readable I think. The patched file was generated programmatically using:
<?php
// Replace two to four chr() concatenations in a row with actual characters.
$out = preg_replace_callback(
'/chr\((\d+)\)\.chr\((\d+)\)(?:\.chr\((\d+)\))?(?:\.chr\((\d+)\))? /',
function ( $m ) {
return "'" . implode( '', array_map( 'chr', array_slice( $m, 1 ) ) ) . "' ";
},
file_get_contents( $argv[1] )
);
// Replace standalone chr(NNN)s with "\xNN".
$out = preg_replace_callback( '/chr\((\d{3})\)/',
function ( $m ) {
return sprintf( '"\x%02x"', intval( $m[1] ) );
},
$out
);
// Combine any resulting concatenated strings ("\xNN"."\xNN" -> "\xNN\xNN").
$out = preg_replace( '/"\."\\\\x/', '\\x', $out );
echo $out;
Attachments (1)
Change History (3)
Note: See
TracTickets for help on using
tickets.
chrs() -> string literals.