Skip to content

Commit daac8f8

Browse files
DanielEScherzerkocsismate
authored andcommitted
gen_stub: stop cloning ExposedDocComment objects
The objects are immutable, and thus can be safely reused when held by an object that gets cloned. Remove the unneeded cloning, and document this fact about the class, noting that the property should be considered `readonly`. Not actually using `readonly` to maintain PHP 7.4 support.
1 parent 418b933 commit daac8f8

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

build/gen_stub.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,9 +2099,6 @@ public function __clone()
20992099
foreach ($this->framelessFunctionInfos as $key => $framelessFunctionInfo) {
21002100
$this->framelessFunctionInfos[$key] = clone $framelessFunctionInfo;
21012101
}
2102-
if ($this->exposedDocComment) {
2103-
$this->exposedDocComment = clone $this->exposedDocComment;
2104-
}
21052102
}
21062103
}
21072104

@@ -3146,9 +3143,6 @@ public function __clone()
31463143
foreach ($this->attributes as $key => $attribute) {
31473144
$this->attributes[$key] = clone $attribute;
31483145
}
3149-
if ($this->exposedDocComment) {
3150-
$this->exposedDocComment = clone $this->exposedDocComment;
3151-
}
31523146
}
31533147
}
31543148

@@ -4011,10 +4005,6 @@ public function __clone()
40114005
foreach ($this->attributes as $key => $attribute) {
40124006
$this->attributes[$key] = clone $attribute;
40134007
}
4014-
4015-
if ($this->exposedDocComment) {
4016-
$this->exposedDocComment = clone $this->exposedDocComment;
4017-
}
40184008
}
40194009

40204010
/**
@@ -4190,8 +4180,10 @@ public function getVariableName(): string {
41904180
}
41914181
}
41924182

4183+
// Instances of ExposedDocComment are immutable and do not need to be cloned
4184+
// when held by an object that is cloned
41934185
class ExposedDocComment {
4194-
private string $docComment;
4186+
private /* readonly */ string $docComment;
41954187

41964188
public function __construct(string $docComment) {
41974189
$this->docComment = $docComment;

0 commit comments

Comments
 (0)