-
Couldn't load subscription status.
- Fork 8k
ext/pgsql: convert regex match, using pcre jit if available and enabled. #15039
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
|
Technically this does seem right, but I wonder about the performance: is the extra effort spent JIT compiling worth it for performing a single match? It seems that the regexes can be quite complex, so it's a bit of a shame that they have to be recompiled each time (already true today, but even more true when JITting). |
|
ok will give it a try |
9fa7735 to
e45f407
Compare
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.
I didn't yet check whether the options are translated correctly to the regex strings. But here's a first round of review.
ext/pgsql/pgsql.c
Outdated
| size_t i; | ||
| zend_hash_destroy(&PGG(connections)); | ||
|
|
||
| for (i = 0; i < 11; i ++) |
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.
You can merge the assignment and declaration of i, we're in C99.
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.
Can you also use a sizeof expression instead of the hardcoded 11? Or alternatively, use a define instead of 11 for both the declaration of the array and this loop?
ext/pgsql/pgsql.c
Outdated
| return FAILURE; | ||
| } | ||
| res = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(str), ZSTR_LEN(str), 0, 0, match_data, php_pcre_mctx()); | ||
| centry->refcount ++; |
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.
Use php_pcre_pce_incref.
ext/pgsql/pgsql.c
Outdated
| res = pcre2_match(centry->re, (PCRE2_SPTR)ZSTR_VAL(str), ZSTR_LEN(str), 0, 0, match_data, php_pcre_mctx()); | ||
| php_pcre_free_match_data(match_data); | ||
| pcre2_code_free(re); | ||
| centry->refcount --; |
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.
Use php_pcre_pce_decref.
ext/pgsql/pgsql.c
Outdated
| } | ||
| res = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(str), ZSTR_LEN(str), 0, 0, match_data, php_pcre_mctx()); | ||
| centry->refcount ++; | ||
| res = pcre2_match(centry->re, (PCRE2_SPTR)ZSTR_VAL(str), ZSTR_LEN(str), 0, 0, match_data, php_pcre_mctx()); |
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.
Use php_pcre_pce_re to obtain re.
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.
cool I did not notice them.
ext/pgsql/pgsql.c
Outdated
| } | ||
|
|
||
| match_data = php_pcre_create_match_data(0, re); | ||
| match_data = php_pcre_create_match_data(0, centry->re); |
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.
Use php_pcre_pce_re to obtain re.
ext/pgsql/pgsql.c
Outdated
| ZEND_GET_MODULE(pgsql) | ||
| #endif | ||
|
|
||
| struct _pcre_cache_entry { |
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.
Please don't import internals from another extension into this extension. I added some suggestions on how to avoid this.
ext/pgsql/pgsql.c
Outdated
| memset(pgsql_globals, 0, sizeof(zend_pgsql_globals)); | ||
| zend_hash_init(&pgsql_globals->connections, 0, NULL, NULL, 1); | ||
|
|
||
| #define ADD_REGEX(reg) pgsql_globals->regexes[i ++] = zend_string_init(reg, strlen(reg), true) |
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.
Can we add a bounds check assertion please?
e45f407 to
985b227
Compare
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.
I think this is right, thanks!
No description provided.