-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
This brings execution time down from 0.91s to 0.86s on the reference benchmark [1]. [1] php#12684 (comment)
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
ext/mbstring/mbstring.c
Outdated
@@ -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 */ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
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)