Skip to content

Commit 0de69fe

Browse files
committed
- MFH pcre_get_compiled_regex_cache() support
1 parent 637a404 commit 0de69fe

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

ext/pcre/php_pcre.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,9 @@ static int pcre_clean_cache(void *data, void *arg TSRMLS_DC)
180180
}
181181
/* }}} */
182182

183-
/* {{{ pcre_get_compiled_regex
184-
*/
185-
PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_options TSRMLS_DC)
186-
{
187-
int compile_options;
188-
return pcre_get_compiled_regex_ex(regex, extra, preg_options, &compile_options TSRMLS_CC);
189-
}
190-
/* }}} */
191-
192-
/* {{{ pcre_get_compiled_regex_ex
183+
/* {{{ pcre_get_compiled_regex_cache
193184
*/
194-
PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC)
185+
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC)
195186
{
196187
pcre *re = NULL;
197188
int coptions = 0;
@@ -203,7 +194,6 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr
203194
char end_delimiter;
204195
char *p, *pp;
205196
char *pattern;
206-
int regex_len;
207197
int do_study = 0;
208198
int poptions = 0;
209199
unsigned const char *tables = NULL;
@@ -230,7 +220,7 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr
230220
*extra = pce->extra;
231221
*preg_options = pce->preg_options;
232222
*compile_options = pce->compile_options;
233-
return pce->re;
223+
return pce;
234224
#if HAVE_SETLOCALE
235225
}
236226
}
@@ -393,9 +383,30 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr
393383
new_entry.tables = tables;
394384
#endif
395385
zend_hash_update(&PCRE_G(pcre_cache), regex, regex_len+1, (void *)&new_entry,
396-
sizeof(pcre_cache_entry), NULL);
386+
sizeof(pcre_cache_entry), (void**)&pce);
397387

398-
return re;
388+
return pce;
389+
}
390+
/* }}} */
391+
392+
/* {{{ pcre_get_compiled_regex
393+
*/
394+
PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_options TSRMLS_DC)
395+
{
396+
int compile_options;
397+
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex, strlen(regex), extra, preg_options, &compile_options TSRMLS_CC);
398+
399+
return pce ? pce->re : NULL;
400+
}
401+
/* }}} */
402+
403+
/* {{{ pcre_get_compiled_regex_ex
404+
*/
405+
PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC)
406+
{
407+
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex, strlen(regex), extra, preg_options, compile_options TSRMLS_CC);
408+
409+
return pce ? pce->re : NULL;
399410
}
400411
/* }}} */
401412

ext/pcre/php_pcre.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ typedef struct {
5757
unsigned const char *tables;
5858
#endif
5959
int compile_options;
60+
int refcount;
6061
} pcre_cache_entry;
6162

63+
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC);
64+
6265
ZEND_BEGIN_MODULE_GLOBALS(pcre)
6366
HashTable pcre_cache;
6467
long backtrack_limit;

0 commit comments

Comments
 (0)