Skip to content

Commit

Permalink
Micro Optimizations - Round #2
Browse files Browse the repository at this point in the history
* .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 phpGH-608.
  • Loading branch information
Ayesh authored Jul 3, 2022
1 parent 1b83fd7 commit d40890d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
backend/mirror.gif
backend/mirror.png
backend/mirror.jpg
backend/mirror.jpg
backend/GeoIP.dat
.idea
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion .router.php
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion images/logo.php
Original file line number Diff line number Diff line change
@@ -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')) {
Expand Down
6 changes: 3 additions & 3 deletions include/prepend.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions include/site.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d40890d

Please sign in to comment.