Skip to content

Commit 30bf69c

Browse files
authored
perf: avoid extra string allocation in get_full_env() (#1382)
* Avoid extra string allocation in get_full_env() We can pass the key directly to add_assoc_str(). * Use add_assoc_str_ex
1 parent f61bc18 commit 30bf69c

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

frankenphp.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,11 @@ PHPAPI void get_full_env(zval *track_vars_array) {
167167
go_string key = full_env.r0[i * 2];
168168
go_string val = full_env.r0[i * 2 + 1];
169169

170-
// create PHP strings for key and value
171-
zend_string *key_str = zend_string_init(key.data, key.len, 0);
170+
// create PHP string for the value
172171
zend_string *val_str = zend_string_init(val.data, val.len, 0);
173172

174173
// add to the associative array
175-
add_assoc_str(track_vars_array, ZSTR_VAL(key_str), val_str);
176-
177-
// release the key string
178-
zend_string_release(key_str);
174+
add_assoc_str_ex(track_vars_array, key.data, key.len, val_str);
179175
}
180176
}
181177

0 commit comments

Comments
 (0)