mirror of
https://github.com/php/php-src.git
synced 2026-04-27 18:23:26 +02:00
Resolve autoglobals as global-fetch CVs when possible
This commit is contained in:
+3
-3
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+4
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user