CVS update: php3/functions
| From: | sas | Date: | Mon, 28 Dec 1998 08:28:40 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-3093@lists.php.net to get a copy of this message | ||
Date: Monday December 28, 1998 @ 3:28
Author: sas
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv2595/functions
Modified Files:
reg.c
Log Message:
replace the remember-last cache for regexes with one using hash tables
Index: php3/functions/reg.c
diff -c php3/functions/reg.c:1.90 php3/functions/reg.c:1.91
*** php3/functions/reg.c:1.90 Sun Dec 27 16:44:37 1998
--- php3/functions/reg.c Mon Dec 28 03:28:40 1998
***************
*** 28,34 ****
| Jaakko Hyvätti <jaakko@hyvatti.iki.fi> |
+----------------------------------------------------------------------+
*/
! /* $Id: reg.c,v 1.90 1998/12/27 21:44:37 zeev Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 28,34 ----
| Jaakko Hyvätti <jaakko@hyvatti.iki.fi> |
+----------------------------------------------------------------------+
*/
! /* $Id: reg.c,v 1.91 1998/12/28 08:28:40 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 53,59 ****
};
static int php3_rinit_regex(INIT_FUNC_ARGS);
! static int php3_rshutdown_regex();
php3_module_entry regexp_module_entry = {
"Regular Expressions", reg_functions, NULL, NULL, php3_rinit_regex,
php3_rshutdown_regex, NULL, STANDARD_MODULE_PROPERTIES
--- 53,59 ----
};
static int php3_rinit_regex(INIT_FUNC_ARGS);
! static int php3_rshutdown_regex(void);
php3_module_entry regexp_module_entry = {
"Regular Expressions", reg_functions, NULL, NULL, php3_rinit_regex,
php3_rshutdown_regex, NULL, STANDARD_MODULE_PROPERTIES
***************
*** 62,96 ****
/* This is the maximum number of (..) constructs we'll generate from a
call to ereg() or eregi() with the optional third argument. */
#define NS 10
#ifndef THREAD_SAFE
! static reg_cache *rc;
! #define php3_regcomp(a,b,c) \
! _php3_regcomp(INTERNAL_FUNCTION_PARAM_PASSTHRU,a,b,c)
! static int _php3_regcomp(INTERNAL_FUNCTION_PARAMETERS,
! regex_t *preg, const char *pattern, int cflags)
{
int r = 0;
!
! if(!rc) {
! rc = emalloc(sizeof *rc);
! php3_list_insert((void *) rc, LE_REGEX);
! rc->pattern = NULL;
! rc->cflags = -1;
! }
! if(!rc->pattern || cflags != rc->cflags ||
! strcmp(pattern, rc->pattern)) {
r = regcomp(preg, pattern, cflags);
if(r == 0) {
! if(rc->cflags != -1) {
! regfree(&rc->preg);
! efree(rc->pattern);
! }
! memcpy(&rc->preg, preg, sizeof(*preg));
! rc->pattern = estrdup(pattern);
rc->cflags = cflags;
}
} else {
memcpy(preg, &rc->preg, sizeof(*preg));
--- 62,92 ----
/* This is the maximum number of (..) constructs we'll generate from a
call to ereg() or eregi() with the optional third argument. */
#define NS 10
+
#ifndef THREAD_SAFE
! typedef struct {
! regex_t preg;
! int cflags;
! } reg_cache;
! static HashTable ht_rc;
! static int php3_regcomp(regex_t *preg, const char *pattern, int cflags)
{
int r = 0;
! int patlen = strlen(pattern);
! reg_cache *rc = NULL;
!
! if(_php3_hash_find(&ht_rc, (char *) pattern, patlen + 1, (void **) &rc)
! == FAILURE || rc->cflags != cflags) {
r = regcomp(preg, pattern, cflags);
if(r == 0) {
! rc = malloc(sizeof *rc);
rc->cflags = cflags;
+ memcpy(&rc->preg, preg, sizeof(*preg));
+ _php3_hash_update(&ht_rc, (char *) pattern, patlen + 1,
+ (void *) rc, sizeof(*rc), NULL);
}
} else {
memcpy(preg, &rc->preg, sizeof(*preg));
***************
*** 600,630 ****
}
/* }}} */
static int php3_rinit_regex(INIT_FUNC_ARGS)
{
#ifndef THREAD_SAFE
! rc = NULL;
#endif
return SUCCESS;
}
! static int php3_rshutdown_regex()
{
#ifndef THREAD_SAFE
! /* add additional shutdown code here */
! if (rc) {
! if (rc->pattern) {
! efree(rc->pattern);
! }
! efree(rc);
! }
#endif
return SUCCESS;
}
-
-
/*
* Local variables:
--- 596,627 ----
}
/* }}} */
+ #ifndef THREAD_SAFE
+ static void _free_reg_cache(void *data)
+ {
+ reg_cache *rc = (reg_cache *) data;
+
+ regfree(&rc->preg);
+ free(rc);
+ }
+ #endif
static int php3_rinit_regex(INIT_FUNC_ARGS)
{
#ifndef THREAD_SAFE
! _php3_hash_init(&ht_rc, 0, NULL, _free_reg_cache, 1);
#endif
return SUCCESS;
}
! static int php3_rshutdown_regex(void)
{
#ifndef THREAD_SAFE
! _php3_hash_destroy(&ht_rc);
#endif
return SUCCESS;
}
/*
* Local variables:
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net