[web-php] master: Micro Optimizations - Round #2
| From: | Ayesh Karunaratne via GitHub | Date: | Sun, 03 Jul 2022 18:39:32 +0000 |
| Subject: | [web-php] master: Micro Optimizations - Round #2 | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-30243@lists.php.net to get a copy of this message | ||
Author: Ayesh Karunaratne (Ayesh)
Committer: GitHub (web-flow)
Pusher: cmb69
Date: 2022-07-03T20:33:22+02:00
Commit: https://github.com/php/web-php/commit/d40890db1b1179c9f4c962503787b8ffc70b9c05
Raw diff: https://github.com/php/web-php/commit/d40890db1b1179c9f4c962503787b8ffc70b9c05.diff
Micro Optimizations - Round #2
* .gitignore: Remove redundant entry
* Minor optimizations with ternary operators
* Use
const instead of define() where appropriate
const is quite faster because of the compile-time optimizations. Because the replaced
statements are not declaring constant conditionally, it's safe to use const in all
of these places.
Closes GH-608.
Changed paths:
M .gitignore
M .router.php
M images/logo.php
M include/prepend.inc
M include/site.inc
Diff:
diff --git a/.gitignore b/.gitignore
index c67111cdc..ff377854a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,6 @@
backend/mirror.gif
backend/mirror.png
backend/mirror.jpg
-backend/mirror.jpg
backend/GeoIP.dat
.idea
.DS_Store
diff --git a/.router.php b/.router.php
index d40eda604..723801a27 100644
--- a/.router.php
+++ b/.router.php
@@ -1,7 +1,7 @@
<?php
$_SERVER["SERVER_ADDR"] = $_SERVER["HTTP_HOST"];
-$filename = isset($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] :
$_SERVER["SCRIPT_NAME"];
+$filename = $_SERVER["PATH_INFO"] ?? $_SERVER["SCRIPT_NAME"];
if (file_exists($_SERVER["DOCUMENT_ROOT"] . $filename)) {
/* This could be an image or whatever, so don't try to compress it */
diff --git a/images/logo.php b/images/logo.php
index 0c64158c5..70b433710 100644
--- a/images/logo.php
+++ b/images/logo.php
@@ -1,6 +1,6 @@
<?php
-$refresh = isset($_GET['refresh']) ? true : false;
+$refresh = isset($_GET['refresh']);
// Be 100% sure the timezone is set
if (ini_get('date.timezone') === '' &&
function_exists('date_default_timezone_set')) {
diff --git a/include/prepend.inc b/include/prepend.inc
index 04adab830..3870dbaf0 100644
--- a/include/prepend.inc
+++ b/include/prepend.inc
@@ -131,9 +131,9 @@ function myphpnet_language($langcode = FALSE)
return false;
}
-define("MYPHPNET_URL_NONE", FALSE);
-define("MYPHPNET_URL_FUNC", 'quickref');
-define("MYPHPNET_URL_MANUAL", 'manual');
+const MYPHPNET_URL_NONE = false;
+const MYPHPNET_URL_FUNC = 'quickref';
+const MYPHPNET_URL_MANUAL = 'manual';
// Set URL search fallback preference
function myphpnet_urlsearch($type = FALSE)
diff --git a/include/site.inc b/include/site.inc
index 2e804a069..b54bd8034 100644
--- a/include/site.inc
+++ b/include/site.inc
@@ -2,16 +2,16 @@
// Define some constants, and $MIRRORS array
// Mirror type constants
-define('MIRROR_DOWNLOAD', 0);
-define('MIRROR_STANDARD', 1);
-define('MIRROR_SPECIAL', 2);
-define('MIRROR_VIRTUAL', 3);
+const MIRROR_DOWNLOAD = 0;
+const MIRROR_STANDARD = 1;
+const MIRROR_SPECIAL = 2;
+const MIRROR_VIRTUAL = 3;
// Mirror status constants
-define('MIRROR_OK', 0);
-define('MIRROR_NOTACTIVE', 1);
-define('MIRROR_OUTDATED', 2);
-define('MIRROR_DOESNOTWORK', 3);
+const MIRROR_OK = 0;
+const MIRROR_NOTACTIVE = 1;
+const MIRROR_OUTDATED = 2;
+const MIRROR_DOESNOTWORK = 3;
$MIRRORS = array(
"https://www.php.net/" => array(