From: Sara Golemon Date: Sat, 20 Jan 2007 20:36:55 +0000 (+0000) Subject: Resolve autoglobals as global-fetch CVs when possible X-Git-Tag: RELEASE_1_0_0RC1~186 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57da96bb42f67a3e412a57b1baf5bcf45c8a8269;p=php Resolve autoglobals as global-fetch CVs when possible --- diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ff58100275..4a6e3d875c 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -267,7 +267,7 @@ static zend_uint get_temporary_variable(zend_op_array *op_array) return (op_array->T)++ * sizeof(temp_variable); } -static int lookup_cv(zend_op_array *op_array, zend_uchar type, zstr name, int name_len) +static int lookup_cv(zend_op_array *op_array, zend_uchar type, zstr name, int name_len TSRMLS_DC) { int i = 0; ulong hash_value = zend_u_inline_hash_func(type, name, name_len+1); @@ -290,6 +290,7 @@ static int lookup_cv(zend_op_array *op_array, zend_uchar type, zstr name, int na op_array->vars[i].name = name; /* estrndup(name, name_len); */ op_array->vars[i].name_len = name_len; op_array->vars[i].hash_value = hash_value; + op_array->vars[i].fetch_type = zend_u_is_auto_global(type, name, name_len TSRMLS_CC) ? ZEND_FETCH_GLOBAL : ZEND_FETCH_LOCAL; return i; } @@ -380,13 +381,12 @@ void fetch_simple_variable_ex(znode *result, znode *varname, int bp, zend_uchar if (varname->op_type == IS_CONST && (Z_TYPE(varname->u.constant) == IS_STRING || Z_TYPE(varname->u.constant) == IS_UNICODE) && - !zend_u_is_auto_global(Z_TYPE(varname->u.constant), Z_UNIVAL(varname->u.constant), Z_UNILEN(varname->u.constant) TSRMLS_CC) && !(Z_UNILEN(varname->u.constant) == (sizeof("this")-1) && ZEND_U_EQUAL(Z_TYPE(varname->u.constant), Z_UNIVAL(varname->u.constant), Z_UNILEN(varname->u.constant), "this", sizeof("this")-1)) && (CG(active_op_array)->last == 0 || CG(active_op_array)->opcodes[CG(active_op_array)->last-1].opcode != ZEND_BEGIN_SILENCE)) { result->op_type = IS_CV; - result->u.var = lookup_cv(CG(active_op_array), Z_TYPE(varname->u.constant), Z_UNIVAL(varname->u.constant), Z_UNILEN(varname->u.constant)); + result->u.var = lookup_cv(CG(active_op_array), Z_TYPE(varname->u.constant), Z_UNIVAL(varname->u.constant), Z_UNILEN(varname->u.constant) TSRMLS_CC); result->u.EA.type = 0; return; } diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 6e272afdec..18c17ed7ca 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -174,6 +174,7 @@ typedef struct _zend_compiled_variable { zstr name; int name_len; ulong hash_value; + zend_uint fetch_type; } zend_compiled_variable; struct _zend_op_array { diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index e92bf2b606..da3cf32520 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -226,8 +226,9 @@ static inline zval *_get_zval_ptr_cv(znode *node, temp_variable *Ts, int type TS if (!*ptr) { zend_compiled_variable *cv = &CV_DEF_OF(node->u.var); zend_uchar utype = UG(unicode)?IS_UNICODE:IS_STRING; + HashTable *symbol_table = (cv->fetch_type == ZEND_FETCH_GLOBAL) ? &EG(symbol_table) : EG(active_symbol_table); - if (zend_u_hash_quick_find(EG(active_symbol_table), utype, cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) { + if (zend_u_hash_quick_find(symbol_table, utype, cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) { switch (type) { case BP_VAR_R: case BP_VAR_UNSET: @@ -296,8 +297,9 @@ static inline zval **_get_zval_ptr_ptr_cv(znode *node, temp_variable *Ts, int ty if (!*ptr) { zend_compiled_variable *cv = &CV_DEF_OF(node->u.var); zend_uchar utype = UG(unicode)?IS_UNICODE:IS_STRING; + HashTable *symbol_table = (cv->fetch_type == ZEND_FETCH_GLOBAL) ? &EG(symbol_table) : EG(active_symbol_table); - if (zend_u_hash_quick_find(EG(active_symbol_table), utype, cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) { + if (zend_u_hash_quick_find(symbol_table, utype, cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) { switch (type) { case BP_VAR_R: case BP_VAR_UNSET: