Skip to content

Commit

Permalink
MDL-35628 performance: Remove dirname() where possible.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mr-russ committed Jun 9, 2016
1 parent 4ee8ef5 commit 1fcf0ca
Show file tree
Hide file tree
Showing 352 changed files with 499 additions and 499 deletions.
2 changes: 1 addition & 1 deletion admin/cli/automated_backups.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

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.'/cronlib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/cli/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

define('CLI_SCRIPT', 1);

require(dirname(dirname(dirname(__FILE__))).'/config.php');
require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php');
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/cli/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

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.'/cronlib.php');

Expand Down
10 changes: 5 additions & 5 deletions admin/cli/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@


// distro specific customisation
$distrolibfile = dirname(dirname(dirname(__FILE__))).'/install/distrolib.php';
$distrolibfile = __DIR__.'/../../install/distrolib.php';
$distro = null;
if (file_exists($distrolibfile)) {
require_once($distrolibfile);
Expand All @@ -100,7 +100,7 @@
}

// Nothing to do if config.php exists
$configfile = dirname(dirname(dirname(__FILE__))).'/config.php';
$configfile = __DIR__.'/../../config.php';
if (file_exists($configfile)) {
require($configfile);
require_once($CFG->libdir.'/clilib.php');
Expand Down Expand Up @@ -159,7 +159,7 @@
global $CFG;
$CFG = new stdClass();
$CFG->lang = 'en';
$CFG->dirroot = dirname(dirname(dirname(__FILE__)));
$CFG->dirroot = dirname(dirname(__DIR__));
$CFG->libdir = "$CFG->dirroot/lib";
$CFG->wwwroot = "http://localhost";
$CFG->httpswwwroot = $CFG->wwwroot;
Expand All @@ -172,7 +172,7 @@
$CFG->debugdisplay = true;
$CFG->debugdeveloper = true;

$parts = explode('/', str_replace('\\', '/', dirname(dirname(__FILE__))));
$parts = explode('/', str_replace('\\', '/', dirname(__DIR__)));
$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
Expand Down Expand Up @@ -244,7 +244,7 @@
'chmod' => isset($distro->directorypermissions) ? sprintf('%04o',$distro->directorypermissions) : '2777', // let distros set dir permissions
'lang' => $CFG->lang,
'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
'dbhost' => empty($distro->dbhost) ? 'localhost' : $distro->dbhost, // let distros set dbhost
'dbname' => 'moodle',
Expand Down
2 changes: 1 addition & 1 deletion admin/cli/install_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
}

// Nothing to do if config.php does not exist
$configfile = dirname(dirname(dirname(__FILE__))).'/config.php';
$configfile = __DIR__.'/../../config.php';
if (!file_exists($configfile)) {
fwrite(STDERR, 'config.php does not exist, can not continue'); // do not localize
fwrite(STDERR, "\n");
Expand Down
2 changes: 1 addition & 1 deletion admin/cli/mysql_collation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

define('CLI_SCRIPT', true);

require(dirname(dirname(dirname(__FILE__))).'/config.php');
require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); // cli only functions

if ($DB->get_dbfamily() !== 'mysql') {
Expand Down
2 changes: 1 addition & 1 deletion admin/cli/mysql_compressed_rows.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

define('CLI_SCRIPT', true);

require(dirname(__FILE__).'/../../config.php');
require(__DIR__.'/../../config.php');
require_once($CFG->libdir . '/clilib.php');

if ($DB->get_dbfamily() !== 'mysql') {
Expand Down
2 changes: 1 addition & 1 deletion admin/cli/mysql_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

define('CLI_SCRIPT', true);

require(dirname(dirname(dirname(__FILE__))).'/config.php');
require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); // cli only functions

if ($DB->get_dbfamily() !== 'mysql') {
Expand Down
2 changes: 1 addition & 1 deletion admin/cli/purge_caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

define('CLI_SCRIPT', true);

require(dirname(dirname(dirname(__FILE__))).'/config.php');
require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php');

list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help'));
Expand Down
2 changes: 1 addition & 1 deletion admin/cli/reset_password.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

define('CLI_SCRIPT', true);

require(dirname(dirname(dirname(__FILE__))).'/config.php');
require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php'); // cli only functions


Expand Down
2 changes: 1 addition & 1 deletion admin/cli/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
define('CLI_SCRIPT', 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.'/upgradelib.php'); // general upgrade/install related functions
require_once($CFG->libdir.'/clilib.php'); // cli only functions
Expand Down
2 changes: 1 addition & 1 deletion admin/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @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');

$action = optional_param('action', '', PARAM_ALPHA);
Expand Down
2 changes: 1 addition & 1 deletion admin/localplugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @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.'/tablelib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/mailout-debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

// Security check.
if (!file_exists(dirname(__FILE__).'/mailout-debugger.enable')) {
if (!file_exists(__DIR__.'/mailout-debugger.enable')) {
mdie("Disabled.");
}
$tmpdir=sys_get_temp_dir(); // default
Expand Down
2 changes: 1 addition & 1 deletion admin/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @copyright 2011 Lancaster University Network Services Limited
* @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->libdir.'/adminlib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/access_control.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// 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');
include_once($CFG->dirroot.'/mnet/lib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @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');

$step = optional_param('step', 'verify', PARAM_ALPHA);
Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// 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');
include_once($CFG->dirroot.'/mnet/lib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/peers.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @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->dirroot.'/mnet/lib.php');
require_once($CFG->dirroot.'/'.$CFG->admin.'/mnet/peer_forms.php');
Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/profilefields.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @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->dirroot . '/admin/mnet/profilefields_form.php');
$mnet = get_mnet_environment();
Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @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->dirroot . '/admin/mnet/services_form.php');
$mnet = get_mnet_environment();
Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/testclient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package mnet
*/
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require(__DIR__.'/../../config.php');
require_once $CFG->dirroot.'/mnet/xmlrpc/client.php';
require_once($CFG->libdir.'/adminlib.php');
include_once($CFG->dirroot.'/mnet/lib.php');
Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/trustedhosts.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
// Allows the admin to configure services for remote hosts

require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/adminlib.php');
include_once($CFG->dirroot.'/mnet/lib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/oauth2callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @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');

// The authorization code generated by the authorization server.
$code = required_param('code', PARAM_RAW);
Expand Down
2 changes: 1 addition & 1 deletion admin/plagiarism.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @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.'/tablelib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @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 . '/filelib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/portfolio.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/portfolio/forms.php');
require_once($CFG->libdir . '/adminlib.php');
Expand Down
2 changes: 1 addition & 1 deletion admin/process_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//error_reporting(0);
//ini_set('display_errors',0);
require_once(dirname(dirname(__FILE__)).'/config.php');
require_once(__DIR__ . '/../config.php');
$tmp = explode('@',$_ENV['RECIPIENT']);
$address = $tmp[0];

Expand Down
2 changes: 1 addition & 1 deletion admin/qbehaviours.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/


require_once(dirname(__FILE__) . '/../config.php');
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/tablelib.php');
Expand Down
2 changes: 1 addition & 1 deletion admin/qtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/


require_once(dirname(__FILE__) . '/../config.php');
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/tablelib.php');
Expand Down
2 changes: 1 addition & 1 deletion admin/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @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.'/tablelib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once(__DIR__ . '/../config.php');
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->libdir . '/adminlib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/repositoryinstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once(__DIR__ . '/../config.php');
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->libdir . '/adminlib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/resetemoticons.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require(dirname(dirname(__FILE__)) . '/config.php');
require(__DIR__ . '/../config.php');
require_once($CFG->libdir.'/adminlib.php');

admin_externalpage_setup('resetemoticons');
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/allow.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @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');

$mode = required_param('mode', PARAM_ALPHANUMEXT);
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/check.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(dirname(__FILE__) . '/../../config.php');
require_once(__DIR__ . '/../../config.php');

$contextid = required_param('contextid', PARAM_INT);

Expand Down
2 changes: 1 addition & 1 deletion admin/roles/define.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @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');

$action = required_param('action', PARAM_ALPHA);
Expand Down
2 changes: 1 addition & 1 deletion admin/roles/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @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->dirroot . '/' . $CFG->admin . '/roles/lib.php');

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/assignmentupgrade/batchupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

define('NO_OUTPUT_BUFFERING', true);

require_once(dirname(__FILE__) . '/../../../config.php');
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentstable.php');
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/assignmentupgrade/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @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->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');

Expand Down
Loading

0 comments on commit 1fcf0ca

Please sign in to comment.