Skip to content

Commit b489506

Browse files
Merge pull request #18251 from kamil-tekiela/micro-optimizations-1
Micro optimizations 1
2 parents a3dd6f1 + 384cccc commit b489506

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

libraries/classes/Config.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,15 @@ class Config
9393
/** @var array */
9494
public array $defaultServer = [];
9595

96+
private bool $isHttps;
97+
9698
private Settings|null $config = null;
9799

100+
public function __construct()
101+
{
102+
$this->isHttps = $this->isHttps();
103+
}
104+
98105
/**
99106
* @param string|null $source source to read config from
100107
*
@@ -776,8 +783,9 @@ public function checkUploadSize(): void
776783
*/
777784
public function isHttps(): bool
778785
{
779-
if ($this->get('is_https') !== null) {
780-
return (bool) $this->get('is_https');
786+
$is_https = $this->get('is_https');
787+
if ($is_https !== null) {
788+
return (bool) $is_https;
781789
}
782790

783791
$url = $this->get('PmaAbsoluteUri');
@@ -887,7 +895,7 @@ public function removeCookie(string $cookieName): bool
887895
time() - 3600,
888896
$this->getRootPath(),
889897
'',
890-
$this->isHttps(),
898+
$this->isHttps,
891899
);
892900
}
893901

@@ -951,7 +959,7 @@ public function setCookie(
951959
'expires' => $validity,
952960
'path' => $this->getRootPath(),
953961
'domain' => '',
954-
'secure' => $this->isHttps(),
962+
'secure' => $this->isHttps,
955963
'httponly' => $httponly,
956964
'samesite' => $cookieSameSite,
957965
];
@@ -982,7 +990,7 @@ public function getCookie(string $cookieName): mixed
982990
*/
983991
public function getCookieName(string $cookieName): string
984992
{
985-
return $cookieName . ( $this->isHttps() ? '_https' : '' );
993+
return $cookieName . ( $this->isHttps ? '_https' : '' );
986994
}
987995

988996
/**

libraries/classes/Config/FormDisplay.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ class FormDisplay
101101

102102
private FormDisplayTemplate $formDisplayTemplate;
103103

104+
private bool $isSetupScript;
105+
104106
/** @param ConfigFile $cf Config file instance */
105107
public function __construct(ConfigFile $cf)
106108
{
107109
$this->formDisplayTemplate = new FormDisplayTemplate($GLOBALS['config']);
108110
$this->configFile = $cf;
111+
$this->isSetupScript = Sanitize::isSetup();
109112
// initialize validators
110113
Validator::getValidators($this->configFile);
111114
}
@@ -724,7 +727,7 @@ public function getDocLink($path): string
724727
return MySQLDocumentation::getDocumentationLink(
725728
'config',
726729
'cfg_' . $this->getOptName($path),
727-
Sanitize::isSetup() ? '../' : './',
730+
$this->isSetupScript ? '../' : './',
728731
);
729732
}
730733

libraries/classes/Url.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public static function getCommonRaw(array $params = [], $divider = '?', $encrypt
228228

229229
$query = self::buildHttpQuery($params, $encrypt);
230230

231-
if (($divider !== '?' && $divider !== '&') || strlen($query) > 0) {
231+
if (($divider !== '?' && $divider !== '&') || $query !== '') {
232232
return $divider . $query;
233233
}
234234

@@ -241,6 +241,10 @@ public static function getCommonRaw(array $params = [], $divider = '?', $encrypt
241241
*/
242242
public static function buildHttpQuery($params, $encrypt = true): string
243243
{
244+
if ($params === []) {
245+
return '';
246+
}
247+
244248
$GLOBALS['config'] ??= null;
245249

246250
$separator = self::getArgSeparator();
@@ -320,7 +324,7 @@ public static function getArgSeparator($encode = 'none'): string
320324
$arg_separator = (string) ini_get('arg_separator.input');
321325
if (str_contains($arg_separator, ';')) {
322326
$separator = ';';
323-
} elseif (strlen($arg_separator) > 0) {
327+
} elseif ($arg_separator !== '') {
324328
$separator = $arg_separator[0];
325329
} else {
326330
$separator = '&';

0 commit comments

Comments
 (0)