1
0
Fork 0

Replace cascading str_replace() calls with strtr()

Replaces cascading str_replace() calls with a single strtr() call that makes it mode readable and provides a micro performance improvement.
Some instances of cascading str_replace() calls were not refactored due to the potential recurring replacement patterns.
pull/9008/head
Ayesh Karunaratne 2020-06-23 04:10:26 +07:00
parent ae44a5963d
commit e3c75b3e87
No known key found for this signature in database
GPG Key ID: 2CA18B2097A7429A
2 changed files with 6 additions and 5 deletions

View File

@ -1064,8 +1064,7 @@ INITIALIZER;
$path = preg_replace('{/+}', '/', preg_quote(trim(strtr($path, '\\', '/'), '/'))); $path = preg_replace('{/+}', '/', preg_quote(trim(strtr($path, '\\', '/'), '/')));
// add support for wildcards * and ** // add support for wildcards * and **
$path = str_replace('\\*\\*', '.+?', $path); $path = strtr($path, array('\\*\\*' => '.+?', '\\*' => '[^/]+?'));
$path = str_replace('\\*', '[^/]+?', $path);
// add support for up-level relative paths // add support for up-level relative paths
$updir = null; $updir = null;

View File

@ -196,9 +196,11 @@ class PluginManager
$className = substr($class, $separatorPos + 1); $className = substr($class, $separatorPos + 1);
} }
$code = preg_replace('{^((?:final\s+)?(?:\s*))class\s+('.preg_quote($className).')}mi', '$1class $2_composer_tmp'.self::$classCounter, $code, 1); $code = preg_replace('{^((?:final\s+)?(?:\s*))class\s+('.preg_quote($className).')}mi', '$1class $2_composer_tmp'.self::$classCounter, $code, 1);
$code = str_replace('__FILE__', var_export($path, true), $code); $code = strtr($code, array(
$code = str_replace('__DIR__', var_export(dirname($path), true), $code); '__FILE__' => var_export($path, true),
$code = str_replace('__CLASS__', var_export($class, true), $code); '__DIR__' => var_export(dirname($path), true),
'__CLASS__' => var_export($class, true),
));
$code = preg_replace('/^\s*<\?(php)?/i', '', $code, 1); $code = preg_replace('/^\s*<\?(php)?/i', '', $code, 1);
eval($code); eval($code);
$class .= '_composer_tmp'.self::$classCounter; $class .= '_composer_tmp'.self::$classCounter;