Skip to content

Avoid temporary string allocations in php_mb_parse_encoding_list() #12714

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
Nov 18, 2023

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Nov 17, 2023

This brings execution time down from 0.91s to 0.86s on the reference benchmark [1]. (The execution time was measured with this PR on top of my earlier open PR #12712)

[1] #12684 (comment)

This brings execution time down from 0.91s to 0.86s on the reference
benchmark [1].

[1] php#12684 (comment)
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -285,6 +285,7 @@ static inline void mb_convert_buf_reset(mb_convert_buf *buf, size_t len)
}

MBFLAPI extern const mbfl_encoding *mbfl_name2encoding(const char *name);
MBFLAPI extern const mbfl_encoding *mbfl_name2encoding_ex(const char *name, size_t name_len);
Copy link
Member

Choose a reason for hiding this comment

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

This new function can be used in more places

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, there are places where we can pass ZSTR_LEN(something). Although that would be a behaviour change because those places seem to allow \0 in strings (the function was never able to handle \0 in strings and silently cut off the string there, but passing ZSTR_LEN would thus change the \0 behaviour). I see you're making a PR to refactor some stuff anyway, so feel free to take a look at those places :)

@@ -300,15 +308,15 @@ static zend_result php_mb_parse_encoding_list(const char *value, size_t value_le
} else {
bool included_auto;
size_t n, size;
char *p1, *endp, *tmpstr;
const char *p1, *endp, *tmpstr;
const mbfl_encoding **entry, **list;

/* copy the value string for work */
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this comment is now redundant, not so?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

@nielsdos nielsdos merged commit 3ad422e into php:master Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants