Commit 1fcf0ca8 authored by Russell Smith's avatar Russell Smith
Browse files

MDL-35628 performance: Remove dirname() where possible.

dirname() is a slow function compared with __DIR__ and using
'/../'.  Moodle has a large number of legacy files that are included
each time a page loads and is not able to use an autoloader as it is
functional code.  This allows those required includes to perform as
best as possible in this situation.
parent 4ee8ef5d
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
define('CLI_SCRIPT', true); define('CLI_SCRIPT', true);
require(dirname(dirname(dirname(__FILE__))).'/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); // cli only functions require_once($CFG->libdir.'/clilib.php'); // cli only functions
require_once($CFG->libdir.'/cronlib.php'); require_once($CFG->libdir.'/cronlib.php');
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
define('CLI_SCRIPT', 1); define('CLI_SCRIPT', 1);
require(dirname(dirname(dirname(__FILE__))).'/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); require_once($CFG->libdir.'/clilib.php');
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
define('CLI_SCRIPT', true); define('CLI_SCRIPT', true);
require(dirname(dirname(dirname(__FILE__))).'/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); // cli only functions require_once($CFG->libdir.'/clilib.php'); // cli only functions
require_once($CFG->libdir.'/cronlib.php'); require_once($CFG->libdir.'/cronlib.php');
......
...@@ -90,7 +90,7 @@ Example: ...@@ -90,7 +90,7 @@ Example:
// distro specific customisation // distro specific customisation
$distrolibfile = dirname(dirname(dirname(__FILE__))).'/install/distrolib.php'; $distrolibfile = __DIR__.'/../../install/distrolib.php';
$distro = null; $distro = null;
if (file_exists($distrolibfile)) { if (file_exists($distrolibfile)) {
require_once($distrolibfile); require_once($distrolibfile);
...@@ -100,7 +100,7 @@ if (file_exists($distrolibfile)) { ...@@ -100,7 +100,7 @@ if (file_exists($distrolibfile)) {
} }
// Nothing to do if config.php exists // Nothing to do if config.php exists
$configfile = dirname(dirname(dirname(__FILE__))).'/config.php'; $configfile = __DIR__.'/../../config.php';
if (file_exists($configfile)) { if (file_exists($configfile)) {
require($configfile); require($configfile);
require_once($CFG->libdir.'/clilib.php'); require_once($CFG->libdir.'/clilib.php');
...@@ -159,7 +159,7 @@ if (version_compare(phpversion(), "5.4.4") < 0) { ...@@ -159,7 +159,7 @@ if (version_compare(phpversion(), "5.4.4") < 0) {
global $CFG; global $CFG;
$CFG = new stdClass(); $CFG = new stdClass();
$CFG->lang = 'en'; $CFG->lang = 'en';
$CFG->dirroot = dirname(dirname(dirname(__FILE__))); $CFG->dirroot = dirname(dirname(__DIR__));
$CFG->libdir = "$CFG->dirroot/lib"; $CFG->libdir = "$CFG->dirroot/lib";
$CFG->wwwroot = "http://localhost"; $CFG->wwwroot = "http://localhost";
$CFG->httpswwwroot = $CFG->wwwroot; $CFG->httpswwwroot = $CFG->wwwroot;
...@@ -172,7 +172,7 @@ $CFG->debug = (E_ALL | E_STRICT); ...@@ -172,7 +172,7 @@ $CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = true; $CFG->debugdisplay = true;
$CFG->debugdeveloper = true; $CFG->debugdeveloper = true;
$parts = explode('/', str_replace('\\', '/', dirname(dirname(__FILE__)))); $parts = explode('/', str_replace('\\', '/', dirname(__DIR__)));
$CFG->admin = array_pop($parts); $CFG->admin = array_pop($parts);
//point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
...@@ -244,7 +244,7 @@ list($options, $unrecognized) = cli_get_params( ...@@ -244,7 +244,7 @@ list($options, $unrecognized) = cli_get_params(
'chmod' => isset($distro->directorypermissions) ? sprintf('%04o',$distro->directorypermissions) : '2777', // let distros set dir permissions 'chmod' => isset($distro->directorypermissions) ? sprintf('%04o',$distro->directorypermissions) : '2777', // let distros set dir permissions
'lang' => $CFG->lang, 'lang' => $CFG->lang,
'wwwroot' => '', 'wwwroot' => '',
'dataroot' => empty($distro->dataroot) ? str_replace('\\', '/', dirname(dirname(dirname(dirname(__FILE__)))).'/moodledata'): $distro->dataroot, // initialised later after including libs or by distro 'dataroot' => empty($distro->dataroot) ? str_replace('\\', '/', dirname(dirname(dirname(__DIR__))).'/moodledata'): $distro->dataroot, // initialised later after including libs or by distro
'dbtype' => empty($distro->dbtype) ? $defaultdb : $distro->dbtype, // let distro skip dbtype selection 'dbtype' => empty($distro->dbtype) ? $defaultdb : $distro->dbtype, // let distro skip dbtype selection
'dbhost' => empty($distro->dbhost) ? 'localhost' : $distro->dbhost, // let distros set dbhost 'dbhost' => empty($distro->dbhost) ? 'localhost' : $distro->dbhost, // let distros set dbhost
'dbname' => 'moodle', 'dbname' => 'moodle',
......
...@@ -72,7 +72,7 @@ if (version_compare(phpversion(), "5.4.4") < 0) { ...@@ -72,7 +72,7 @@ if (version_compare(phpversion(), "5.4.4") < 0) {
} }
// Nothing to do if config.php does not exist // Nothing to do if config.php does not exist
$configfile = dirname(dirname(dirname(__FILE__))).'/config.php'; $configfile = __DIR__.'/../../config.php';
if (!file_exists($configfile)) { if (!file_exists($configfile)) {
fwrite(STDERR, 'config.php does not exist, can not continue'); // do not localize fwrite(STDERR, 'config.php does not exist, can not continue'); // do not localize
fwrite(STDERR, "\n"); fwrite(STDERR, "\n");
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
define('CLI_SCRIPT', true); define('CLI_SCRIPT', true);
require(dirname(dirname(dirname(__FILE__))).'/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); // cli only functions require_once($CFG->libdir.'/clilib.php'); // cli only functions
if ($DB->get_dbfamily() !== 'mysql') { if ($DB->get_dbfamily() !== 'mysql') {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
define('CLI_SCRIPT', true); define('CLI_SCRIPT', true);
require(dirname(__FILE__).'/../../config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir . '/clilib.php'); require_once($CFG->libdir . '/clilib.php');
if ($DB->get_dbfamily() !== 'mysql') { if ($DB->get_dbfamily() !== 'mysql') {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
define('CLI_SCRIPT', true); define('CLI_SCRIPT', true);
require(dirname(dirname(dirname(__FILE__))).'/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); // cli only functions require_once($CFG->libdir.'/clilib.php'); // cli only functions
if ($DB->get_dbfamily() !== 'mysql') { if ($DB->get_dbfamily() !== 'mysql') {
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
define('CLI_SCRIPT', true); define('CLI_SCRIPT', true);
require(dirname(dirname(dirname(__FILE__))).'/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); require_once($CFG->libdir.'/clilib.php');
list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help'));
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
define('CLI_SCRIPT', true); define('CLI_SCRIPT', true);
require(dirname(dirname(dirname(__FILE__))).'/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); // cli only functions require_once($CFG->libdir.'/clilib.php'); // cli only functions
......
...@@ -38,7 +38,7 @@ if (function_exists('opcache_reset') and !isset($_SERVER['REMOTE_ADDR'])) { ...@@ -38,7 +38,7 @@ if (function_exists('opcache_reset') and !isset($_SERVER['REMOTE_ADDR'])) {
define('CLI_SCRIPT', true); define('CLI_SCRIPT', true);
define('CACHE_DISABLE_ALL', true); define('CACHE_DISABLE_ALL', true);
require(dirname(dirname(dirname(__FILE__))).'/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
require_once($CFG->libdir.'/clilib.php'); // cli only functions require_once($CFG->libdir.'/clilib.php'); // cli only functions
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once(dirname(__FILE__) . '/../config.php'); require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->libdir . '/adminlib.php');
$action = optional_param('action', '', PARAM_ALPHA); $action = optional_param('action', '', PARAM_ALPHA);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once(dirname(dirname(__FILE__)) . '/config.php'); require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php'); require_once($CFG->libdir.'/tablelib.php');
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
*/ */
// Security check. // Security check.
if (!file_exists(dirname(__FILE__).'/mailout-debugger.enable')) { if (!file_exists(__DIR__.'/mailout-debugger.enable')) {
mdie("Disabled."); mdie("Disabled.");
} }
$tmpdir=sys_get_temp_dir(); // default $tmpdir=sys_get_temp_dir(); // default
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* @copyright 2011 Lancaster University Network Services Limited * @copyright 2011 Lancaster University Network Services Limited
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once(dirname(__FILE__) . '/../config.php'); require_once(__DIR__ . '/../config.php');
require_once($CFG->dirroot . '/message/lib.php'); require_once($CFG->dirroot . '/message/lib.php');
require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/adminlib.php');
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Allows the admin to control user logins from remote moodles. // Allows the admin to control user logins from remote moodles.
require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once(__DIR__ . '/../../config.php');
require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/adminlib.php');
include_once($CFG->dirroot.'/mnet/lib.php'); include_once($CFG->dirroot.'/mnet/lib.php');
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->libdir . '/adminlib.php');
$step = optional_param('step', 'verify', PARAM_ALPHA); $step = optional_param('step', 'verify', PARAM_ALPHA);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Allows the admin to configure mnet stuff // Allows the admin to configure mnet stuff
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/adminlib.php');
include_once($CFG->dirroot.'/mnet/lib.php'); include_once($CFG->dirroot.'/mnet/lib.php');
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/mnet/lib.php'); require_once($CFG->dirroot.'/mnet/lib.php');
require_once($CFG->dirroot.'/'.$CFG->admin.'/mnet/peer_forms.php'); require_once($CFG->dirroot.'/'.$CFG->admin.'/mnet/peer_forms.php');
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require(dirname(dirname(dirname(__FILE__))).'/config.php'); require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot . '/admin/mnet/profilefields_form.php'); require_once($CFG->dirroot . '/admin/mnet/profilefields_form.php');
$mnet = get_mnet_environment(); $mnet = get_mnet_environment();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment