ext/pcre: simplify locale char table lookup and pattern info error ha…#21312
Open
devnexen wants to merge 2 commits intophp:masterfrom
Open
ext/pcre: simplify locale char table lookup and pattern info error ha…#21312devnexen wants to merge 2 commits intophp:masterfrom
devnexen wants to merge 2 commits intophp:masterfrom
Conversation
ndossche
requested changes
Feb 27, 2026
ext/pcre/php_pcre.c
Outdated
|
|
||
| if (key != regex) { | ||
| tables = (uint8_t *)zend_hash_find_ptr(&char_tables, BG(ctype_string)); | ||
| tables = (uint8_t *)zend_hash_str_find_ptr(&char_tables, ZSTR_VAL(BG(ctype_string)), ZSTR_LEN(BG(ctype_string))); |
Member
There was a problem hiding this comment.
This will be slower because it will repeatedly hash the string
ext/pcre/php_pcre.c
Outdated
| zend_hash_add_ptr(&char_tables, _k, (void *)tables); | ||
| zend_string_release(_k); | ||
|
|
||
| zend_hash_str_add_new_ptr(&char_tables, ZSTR_VAL(BG(ctype_string)), ZSTR_LEN(BG(ctype_string)), (void *)tables); |
Member
There was a problem hiding this comment.
Is this actually faster? There are some trade-offs here
If you want to make this code faster then perhaps using the _lookup variant is better anyway
|
|
||
| rc = pcre2_pattern_info(re, PCRE2_INFO_NAMECOUNT, &new_entry.name_count); | ||
| if (rc < 0) { | ||
| if ((rc = pcre2_pattern_info(re, PCRE2_INFO_CAPTURECOUNT, &new_entry.capture_count)) < 0 || |
Member
There was a problem hiding this comment.
This change seems good but it doesn't belong to the same commit
9741a9b to
2c32857
Compare
ndossche
reviewed
Feb 27, 2026
ext/pcre/php_pcre.c
Outdated
| zend_string_release(_k); | ||
| ZVAL_PTR(zv, (void *)tables); | ||
| } else { | ||
| tables = (uint8_t *)Z_PTR_P(zv); |
Member
There was a problem hiding this comment.
I don't think the cast is necessary.
| GC_MAKE_PERSISTENT_LOCAL(_k); | ||
| zend_hash_add_ptr(&char_tables, _k, (void *)tables); | ||
| zend_string_release(_k); | ||
| ZVAL_PTR(zv, (void *)tables); |
Member
There was a problem hiding this comment.
I don't think the cast is necessary.
Member
Author
There was a problem hiding this comment.
hmmm I have const qualifier warning if I do not.
Replace the separate zend_hash_find_ptr + zend_string_init + zend_hash_add_ptr + zend_string_release sequence with a single zend_hash_str_lookup() call which handles find-or-insert in one hash traversal and manages persistent key creation internally.
2c32857 to
bbaa557
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ndling
Use zend_hash_str_find_ptr/zend_hash_str_add_new_ptr for the locale character tables hash, avoiding a temporary zend_string allocation. Consolidate two pcre2_pattern_info calls with identical error handling into a single conditional.