@@ -45,8 +45,9 @@ final class Uri
4545 private readonly array $ rawComponents ;
4646 private readonly string $ rawUri ;
4747 /** @var Components */
48- private array $ normalizedComponents ;
49- private ?string $ normalizedUri ;
48+ private array $ normalizedComponents = self ::DEFAULT_COMPONENTS ;
49+ private ?string $ normalizedUri = null ;
50+ private bool $ isNormalized ;
5051
5152 /**
5253 * @throws InvalidUriException
@@ -65,8 +66,7 @@ public function __construct(string $uri, ?string $baseUri = null)
6566
6667 $ this ->rawComponents = self ::addUserInfo ($ components );
6768 $ this ->rawUri = $ uri ;
68- $ this ->normalizedUri = null ;
69- $ this ->normalizedComponents = self ::DEFAULT_COMPONENTS ;
69+ $ this ->isNormalized = false ;
7070 }
7171
7272 /**
@@ -119,10 +119,11 @@ public static function parse(string $uri, ?string $baseUri = null): ?Uri
119119
120120 private function setNormalizedComponents (): void
121121 {
122- if (self :: DEFAULT_COMPONENTS === $ this ->normalizedComponents ) {
122+ if (! $ this ->isNormalized ) {
123123 $ this ->normalizedComponents = self ::addUserInfo (UriString::parseNormalized ($ this ->toRawString ()));
124124 // We convert the host separately because the current RFC does not handle IDNA
125125 $ this ->normalizedComponents ['host ' ] = Encoder::normalizeHost ($ this ->rawComponents ['host ' ]);
126+ $ this ->isNormalized = true ;
126127 }
127128 }
128129
@@ -389,8 +390,7 @@ public function __unserialize(array $data): void
389390
390391 $ this ->rawComponents = $ uri ->rawComponents ;
391392 $ this ->rawUri = $ uri ->rawUri ;
392- $ this ->normalizedComponents = self ::DEFAULT_COMPONENTS ;
393- $ this ->normalizedUri = null ;
393+ $ this ->isNormalized = false ;
394394 }
395395
396396 /**
0 commit comments