Browse Source

optimized function_table/class_table by caching hash value

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@506 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 14 years ago
parent
commit
7dcd2de319
  1. 4
      processor/processor.m4
  2. 16
      utils.c
  3. 6
      utils.h
  4. 10
      xcache.c
  5. 10
      xcache.h

4
processor/processor.m4

@ -698,6 +698,7 @@ DEF_STRUCT_P_FUNC(`xc_constinfo_t', , `dnl {{{
IFRESTORE(`COPY(key)', `
PROC_ZSTRING_N(type, key, key_size)
')
DISPATCH(ulong, h)
STRUCT(zend_constant, constant)
')
dnl }}}
@ -710,6 +711,7 @@ DEF_STRUCT_P_FUNC(`xc_funcinfo_t', , `dnl {{{
IFRESTORE(`COPY(key)', `
PROC_ZSTRING_N(type, key, key_size)
')
DISPATCH(ulong, h)
STRUCT(zend_function, func)
')
dnl }}}
@ -721,6 +723,7 @@ DEF_STRUCT_P_FUNC(`xc_classinfo_t', , `dnl {{{
IFRESTORE(`COPY(key)', `
PROC_ZSTRING_N(type, key, key_size)
')
DISPATCH(ulong, h)
#ifdef ZEND_ENGINE_2
STRUCT_P(zend_class_entry, cest)
#else
@ -738,6 +741,7 @@ DEF_STRUCT_P_FUNC(`xc_autoglobal_t', , `dnl {{{
IFRESTORE(`COPY(key)', `
PROC_ZSTRING_L(type, key, key_len)
')
DISPATCH(ulong, h)
')
dnl }}}
#endif

16
utils.c

@ -424,7 +424,7 @@ static int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table,
/* }}} */
#ifdef HAVE_XCACHE_CONSTANT
void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len TSRMLS_DC) /* {{{ */
void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */
{
if (zend_u_hash_add(EG(zend_constants), type, key, len,
constant, sizeof(zend_constant),
@ -444,7 +444,7 @@ void xc_install_constant(char *filename, zend_constant *constant, zend_uchar typ
}
/* }}} */
#endif
void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len TSRMLS_DC) /* {{{ */
void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */
{
zend_bool istmpkey;
@ -474,7 +474,7 @@ void xc_install_function(char *filename, zend_function *func, zend_uchar type, z
}
}
/* }}} */
ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len TSRMLS_DC) /* {{{ */
ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */
{
zend_bool istmpkey;
zend_class_entry *cep = CestToCePtr(*cest);
@ -486,7 +486,7 @@ ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int op
istmpkey = ZSTR_S(key)[0] == 0;
#endif
if (istmpkey) {
zend_u_hash_update(CG(class_table), type, key, len,
zend_u_hash_quick_update(CG(class_table), type, key, len, h,
cest, sizeof(xc_cest_t),
ZESW(&stored_ce_ptr, NULL)
);
@ -494,7 +494,7 @@ ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int op
xc_do_early_binding(CG(active_op_array), CG(class_table), oplineno TSRMLS_CC);
}
}
else if (zend_u_hash_add(CG(class_table), type, key, len,
else if (zend_u_hash_quick_add(CG(class_table), type, key, len, h,
cest, sizeof(xc_cest_t),
ZESW(&stored_ce_ptr, NULL)
) == FAILURE) {
@ -684,7 +684,7 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t instal
while (b != NULL) {
zend_constant *c = (zend_constant*) b->pData;
xc_install_constant(sandbox->filename, c,
BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength TSRMLS_CC);
BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC);
b = b->pListNext;
}
#endif
@ -694,7 +694,7 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t instal
while (b != NULL) {
zend_function *func = (zend_function*) b->pData;
xc_install_function(sandbox->filename, func,
BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength TSRMLS_CC);
BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC);
b = b->pListNext;
}
@ -702,7 +702,7 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t instal
/* install class */
while (b != NULL) {
xc_install_class(sandbox->filename, (xc_cest_t*) b->pData, -1,
BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength TSRMLS_CC);
BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC);
b = b->pListNext;
}

6
utils.h

@ -71,10 +71,10 @@ int xc_foreach_early_binding_class(zend_op_array *op_array, void (*callback)(zen
/* installer */
#ifdef HAVE_XCACHE_CONSTANT
void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len TSRMLS_DC);
void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC);
#endif
void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len TSRMLS_DC);
ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len TSRMLS_DC);
void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC);
ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC);
/* sandbox */
typedef struct {

10
xcache.c

@ -621,7 +621,7 @@ static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRM
for (i = 0; i < p->constinfo_cnt; i ++) {
xc_constinfo_t *ci = &p->constinfos[i];
xc_install_constant(xce->name.str.val, &ci->constant,
UNISW(0, ci->type), ci->key, ci->key_size TSRMLS_CC);
UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
}
#endif
@ -629,7 +629,7 @@ static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRM
for (i = 0; i < p->funcinfo_cnt; i ++) {
xc_funcinfo_t *fi = &p->funcinfos[i];
xc_install_function(xce->name.str.val, &fi->func,
UNISW(0, fi->type), fi->key, fi->key_size TSRMLS_CC);
UNISW(0, fi->type), fi->key, fi->key_size, fi->h TSRMLS_CC);
}
/* install class */
@ -646,7 +646,7 @@ static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRM
new_cest_ptrs[i] =
#endif
xc_install_class(xce->name.str.val, &ci->cest, ci->oplineno,
UNISW(0, ci->type), ci->key, ci->key_size TSRMLS_CC);
UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
}
#ifdef ZEND_ENGINE_2_1
@ -655,7 +655,7 @@ static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRM
xc_autoglobal_t *aginfo = &p->autoglobals[i];
/*
zend_auto_global *auto_global;
if (zend_u_hash_find(CG(auto_globals), aginfo->type, aginfo->key, aginfo->key_len+1, (void **) &auto_global)==SUCCESS) {
if (zend_u_hash_quick_find(CG(auto_globals), aginfo->type, aginfo->key, aginfo->key_len+1, aginfo->h, (void **) &auto_global)==SUCCESS) {
if (auto_global->armed) {
auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC);
}
@ -1086,6 +1086,7 @@ static zend_op_array *xc_compile_php(xc_entry_data_php_t *php, zend_file_handle
ZSTR_U(data->key) = BUCKET_KEY_U(b); \
} \
data->key_size = b->nKeyLength; \
data->h = b->h; \
} \
} while(0)
@ -1118,6 +1119,7 @@ static zend_op_array *xc_compile_php(xc_entry_data_php_t *php, zend_file_handle
ZSTR_U(data->key) = BUCKET_KEY_U(b);
}
data->key_len = b->nKeyLength - 1;
data->h = b->h;
}
}
#endif

10
xcache.h

@ -140,9 +140,15 @@ typedef char *zstr;
# define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
# define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
zend_hash_quick_add(ht, arKey, nKeyLength, h, pData, nDataSize, pDest)
# define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
# define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
zend_hash_quick_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest)
# define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
zend_hash_find(ht, arKey, nKeyLength, pData)
@ -226,6 +232,7 @@ typedef struct {
#endif
zstr key;
zend_uint key_size;
ulong h;
xc_cest_t cest;
int oplineno;
} xc_classinfo_t;
@ -238,6 +245,7 @@ typedef struct {
#endif
zstr key;
zend_uint key_size;
ulong h;
zend_constant constant;
} xc_constinfo_t;
/* }}} */
@ -249,6 +257,7 @@ typedef struct {
#endif
zstr key;
zend_uint key_size;
ulong h;
zend_function func;
} xc_funcinfo_t;
/* }}} */
@ -260,6 +269,7 @@ typedef struct {
#endif
zstr key;
zend_uint key_len;
ulong h;
} xc_autoglobal_t;
/* }}} */
#endif

Loading…
Cancel
Save