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
......@@ -24,7 +24,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_ALPHANUMEXT);
......
......@@ -83,7 +83,7 @@ class generate_all_documentation extends XMLDBAction {
$doc = new DOMDocument();
$xsl = new XSLTProcessor();
$doc->load(dirname(__FILE__).'/../generate_documentation/xmldb.xsl');
$doc->load(__DIR__.'/../generate_documentation/xmldb.xsl');
$xsl->importStyleSheet($doc);
$dbdirs = get_db_directories();
......
......@@ -87,7 +87,7 @@ class generate_documentation extends XMLDBAction {
$doc = new DOMDocument();
$xsl = new XSLTProcessor();
$doc->load(dirname(__FILE__).'/xmldb.xsl');
$doc->load(__DIR__.'/xmldb.xsl');
$xsl->importStyleSheet($doc);
$doc->load($path);
......
......@@ -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');
......
......@@ -42,7 +42,7 @@
define('CLI_SCRIPT', true);
require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
require(__DIR__.'/../../../config.php');
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->libdir.'/clilib.php');
......
......@@ -46,7 +46,7 @@
define('CLI_SCRIPT', true);
require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); // global moodle config file.
require(__DIR__.'/../../../config.php'); // global moodle config file.
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->libdir.'/clilib.php');
......
<?php
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require(__DIR__.'/../../config.php');
//HTTPS is required in this page when $CFG->loginhttps enabled
$PAGE->https_required();
......
<?php
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require(__DIR__.'/../../config.php');
//HTTPS is required in this page when $CFG->loginhttps enabled
$PAGE->https_required();
......
......@@ -6,7 +6,7 @@
// of the webserver.
define('NO_MOODLE_COOKIES', true);
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require(__DIR__.'/../../config.php');
//HTTPS is required in this page when $CFG->loginhttps enabled
$PAGE->https_required();
......
......@@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once __DIR__ . '/../../config.php';
// grab the GET params - wantsurl could be anything - take it
// with PARAM_RAW
......
......@@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once __DIR__ . '/../../config.php';
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
// grab the GET params
......
......@@ -23,7 +23,7 @@
*/
require_once('../config.php');
require_once(dirname(__FILE__) . '/backupfilesedit_form.php');
require_once(__DIR__ . '/backupfilesedit_form.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
require_once($CFG->dirroot . '/repository/lib.php');
......
......@@ -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(__FILE__) .'/../xmlbase.php');
require_once(__DIR__ .'/../xmlbase.php');
require_once('cssparser.php');
require_once('pathutils.php');
......
......@@ -53,7 +53,7 @@ function errorHandler($errno, $errstr, $errfile, $errline) {
*/
function file_mime_type ($file, $default_type = 'application/octet-stream'){
$ftype = $default_type;
$magic_path = dirname(__FILE__)
$magic_path = __DIR__
. DIRECTORY_SEPARATOR
. '..'
. DIRECTORY_SEPARATOR
......
......@@ -33,7 +33,7 @@ require_once($CFG->dirroot . '/backup/util/dbops/backup_dbops.class.php');
require_once($CFG->dirroot . '/backup/util/dbops/backup_controller_dbops.class.php');
require_once($CFG->dirroot . '/backup/util/dbops/restore_dbops.class.php');
require_once($CFG->dirroot . '/backup/util/xml/contenttransformer/xml_contenttransformer.class.php');
require_once(dirname(__FILE__) . '/handlerlib.php');
require_once(__DIR__ . '/handlerlib.php');
/**
* Converter of Moodle 1.9 backup into Moodle 2.x format
......
......@@ -23,7 +23,7 @@
*/
require_once('../config.php');
require_once(dirname(__FILE__) . '/restorefile_form.php');
require_once(__DIR__ . '/restorefile_form.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
// current context
......
......@@ -24,7 +24,7 @@
* @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
*/
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/badgeslib.php');
$badgeid = required_param('id', PARAM_INT);
......
......@@ -26,7 +26,7 @@
define('AJAX_SCRIPT', true);
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/badgeslib.php');
require_login();
......
......@@ -27,7 +27,7 @@
define('AJAX_SCRIPT', true);
define('NO_MOODLE_COOKIES', true); // No need for a session here.
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once(__DIR__ . '/../config.php');
if (empty($CFG->enablebadges)) {
print_error('badgesdisabled', 'badges');
......
......@@ -24,7 +24,7 @@
* @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
*/
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/badgeslib.php');
require_once($CFG->dirroot . '/badges/lib/awardlib.php');
......
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