Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1eadf55

Browse files
Arginfo: avoid using temporary zvals for initializing attribute values (#19141)
Instead of * adding a zval on the stack * initializing it * copying the value to the attribute Just initialize the value directly in the zend_attribute_arg
1 parent c55f142 commit 1eadf55

23 files changed

+154
-419
lines changed

‎Zend/zend_attributes_arginfo.h‎

Lines changed: 7 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Zend/zend_constants_arginfo.h‎

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/gen_stub.php‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,11 +2358,14 @@ private function __construct($value, SimpleType $type, Expr $expr, array $origin
23582358
$this->isUnknownConstValue = $isUnknownConstValue;
23592359
}
23602360

2361-
public function initializeZval(string $zvalName): string
2361+
public function initializeZval(string $zvalName, bool$alreadyExists = false, string$forStringDef = ''): string
23622362
{
23632363
$cExpr = $this->getCExpr();
23642364

2365-
$code = "\tzval $zvalName;\n";
2365+
$code = '';
2366+
if (!$alreadyExists) {
2367+
$code = "\tzval $zvalName;\n";
2368+
}
23662369

23672370
if ($this->type->isNull()) {
23682371
$code .= "\tZVAL_NULL(&$zvalName);\n";
@@ -2382,8 +2385,11 @@ public function initializeZval(string $zvalName): string
23822385
if ($cExpr === '""') {
23832386
$code .= "\tZVAL_EMPTY_STRING(&$zvalName);\n";
23842387
} else {
2385-
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($cExpr, strlen($cExpr), 1);\n";
2386-
$code .= "\tZVAL_STR(&$zvalName, {$zvalName}_str);\n";
2388+
if ($forStringDef === '') {
2389+
$forStringDef = "{$zvalName}_str";
2390+
}
2391+
$code .= "\tzend_string *$forStringDef = zend_string_init($cExpr, strlen($cExpr), 1);\n";
2392+
$code .= "\tZVAL_STR(&$zvalName, $forStringDef);\n";
23872393
}
23882394
} elseif ($this->type->isArray()) {
23892395
if ($cExpr == '[]') {
@@ -2821,7 +2827,8 @@ private function getClassConstDeclaration(EvaluatedValue $value, array $allConst
28212827
{
28222828
$constName = $this->name->getDeclarationName();
28232829

2824-
$zvalCode = $value->initializeZval("const_{$constName}_value", $allConstInfos);
2830+
// TODO $allConstInfos is unused
2831+
$zvalCode = $value->initializeZval("const_{$constName}_value");
28252832

28262833
$code = "\n" . $zvalCode;
28272834

@@ -3378,9 +3385,11 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC
33783385
}
33793386
if ($initValue === '') {
33803387
$value = EvaluatedValue::createFromExpression($arg->value, null, null, $allConstInfos);
3381-
$zvalName = "attribute_{$escapedAttributeName}_{$nameSuffix}_arg$i";
3382-
$code .= $value->initializeZval($zvalName);
3383-
$code .= "\tZVAL_COPY_VALUE(&attribute_{$escapedAttributeName}_{$nameSuffix}->args[$i].value, &$zvalName);\n";
3388+
$code .= $value->initializeZval(
3389+
"attribute_{$escapedAttributeName}_{$nameSuffix}->args[$i].value",
3390+
true,
3391+
"attribute_{$escapedAttributeName}_{$nameSuffix}_arg{$i}_str"
3392+
);
33843393
} else {
33853394
$code .= $initValue;
33863395
}

‎ext/curl/curl_arginfo.h‎

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /