Commit a7a3a5f1d25 for php.net
commit a7a3a5f1d2530191554ea249f5bdf1277501eb43
Author: Tim Düsterhus <tim@bastelstu.be>
Date: Mon Jun 22 00:30:58 2026 +0200
zend_ast: Clean up `zend_ast_export_quoted_str()` (#22393)
* zend_ast: Make `s` a `const zend_string*` in `zend_ast_export_quoted_str()`
Following php/php-src#22350.
* zend_ast: Reduce variable scope in `zend_ast_export_*str()`
diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c
index cb27d9b7459..d3ce419c737 100644
--- a/Zend/zend_ast.c
+++ b/Zend/zend_ast.c
@@ -1578,9 +1578,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
static ZEND_COLD void zend_ast_export_str(smart_str *str, const zend_string *s)
{
- size_t i;
-
- for (i = 0; i < ZSTR_LEN(s); i++) {
+ for (size_t i = 0; i < ZSTR_LEN(s); i++) {
unsigned char c = ZSTR_VAL(s)[i];
if (c == '\'' || c == '\\') {
smart_str_appendc(str, '\\');
@@ -1593,9 +1591,7 @@ static ZEND_COLD void zend_ast_export_str(smart_str *str, const zend_string *s)
static ZEND_COLD void zend_ast_export_qstr(smart_str *str, char quote, const zend_string *s)
{
- size_t i;
-
- for (i = 0; i < ZSTR_LEN(s); i++) {
+ for (size_t i = 0; i < ZSTR_LEN(s); i++) {
unsigned char c = ZSTR_VAL(s)[i];
if (c < ' ') {
switch (c) {
@@ -1636,12 +1632,11 @@ static ZEND_COLD void zend_ast_export_qstr(smart_str *str, char quote, const zen
}
}
-static ZEND_COLD void zend_ast_export_quoted_str(smart_str *str, zend_string *s)
+static ZEND_COLD void zend_ast_export_quoted_str(smart_str *str, const zend_string *s)
{
- size_t i;
-
- for (i = 0; i < ZSTR_LEN(s); i++) {
- if ((unsigned char) ZSTR_VAL(s)[i] < ' ') {
+ for (size_t i = 0; i < ZSTR_LEN(s); i++) {
+ unsigned char c = ZSTR_VAL(s)[i];
+ if (c < ' ') {
smart_str_appendc(str, '"');
zend_ast_export_qstr(str, '"', s);
smart_str_appendc(str, '"');