Skip to content

Avoid extra string allocation in get_full_env() #1382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2025
Merged

Conversation

nielsdos
Copy link
Member

We can pass the key directly to add_assoc_str().

We can pass the key directly to add_assoc_str().
frankenphp.c Outdated

// release the key string
zend_string_release(key_str);
add_assoc_str(track_vars_array, key.data, val_str);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can even use add_assoc_str_ex to avoid a strlen call, as I suppose that we length of the key would be the same as strlen on this as there won't be any NUL bytes. Or am I mistaken here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Good catch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I pushed that now, as a separate commit (it's a habit so it makes it clearer on GitHub what has changed since last review/remark, I can adapt to what you're used as convention as well but this is what I do in php-src).
On approve I can either squash it for you and use the conventional commit format. Just let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do the same thing, and we usually squash for you on merge.

@dunglas dunglas merged commit 30bf69c into php:main Feb 18, 2025
37 of 40 checks passed
@dunglas
Copy link
Member

dunglas commented Feb 18, 2025

Thanks @nielsdos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants