Permalink
Browse files

UrlImmutable: authority is pregenerated (microoptimization)

  • Loading branch information...
dg committed Feb 11, 2019
1 parent 12b5f95 commit 6437f73363c90a210ec1ee9bef07551d8acd65f6
Showing with 15 additions and 10 deletions.
  1. +15 −10 src/Http/UrlImmutable.php
@@ -66,6 +66,9 @@ class UrlImmutable implements \JsonSerializable
/** @var string */
private $fragment = '';
/** @var string */
private $authority = '';
/**
* @param string|self|Url $url
@@ -83,6 +86,16 @@ public function __construct($url)
} elseif ($url !== null) {
throw new Nette\InvalidArgumentException;
}
$this->authority = $this->host === ''
? ''
: ($this->user !== ''
? rawurlencode($this->user) . ($this->password === '' ? '' : ':' . rawurlencode($this->password)) . '@'
: '')
. $this->host
. ($this->port && (!isset(Url::$defaultPorts[$this->scheme]) || $this->port !== Url::$defaultPorts[$this->scheme])
? ':' . $this->port
: '');
}
@@ -173,15 +186,7 @@ public function getAbsoluteUrl(): string
*/
public function getAuthority(): string
{
return $this->host === ''
? ''
: ($this->user !== ''
? rawurlencode($this->user) . ($this->password === '' ? '' : ':' . rawurlencode($this->password)) . '@'
: '')
. $this->host
. ($this->port && (!isset(Url::$defaultPorts[$this->scheme]) || $this->port !== Url::$defaultPorts[$this->scheme])
? ':' . $this->port
: '');
return $this->authority;
}
@@ -191,7 +196,7 @@ public function getAuthority(): string
public function getHostUrl(): string
{
return ($this->scheme ? $this->scheme . ':' : '')
. (($authority = $this->getAuthority()) || $this->scheme ? '//' . $authority : '');
. ($this->authority || $this->scheme ? '//' . $this->authority : '');
}

0 comments on commit 6437f73

Please sign in to comment.