]> granicus.if.org Git - php/commitdiff
- Improve performance of functions that use $GLOBALS[]
authorAndi Gutmans <andi@php.net>
Sun, 20 Jan 2002 20:42:15 +0000 (20:42 +0000)
committerAndi Gutmans <andi@php.net>
Sun, 20 Jan 2002 20:42:15 +0000 (20:42 +0000)
- Please check this and make sure it doesn't break anything.

Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_execute_API.c
Zend/zend_language_parser.y
Zend/zend_opcode.c

index 55a3e5e756b3ab18d8afb051fe66d7477ff4d97e..2a02ac60f65d8c91af4450cebaab67c1bcb85427 100644 (file)
@@ -82,6 +82,7 @@ void zend_init_compiler_data_structures(TSRMLS_D)
        CG(in_compilation) = 0;
        init_compiler_declarables(TSRMLS_C);
        CG(throw_list) = NULL;
+       zend_register_auto_global("GLOBALS", sizeof("GLOBALS")-1 TSRMLS_CC);
 }
 
 
@@ -195,18 +196,6 @@ void zend_do_binary_assign_op(int op, znode *result, znode *op1, znode *op2 TSRM
 }
 
 
-
-void zend_do_fetch_globals(znode *varname TSRMLS_DC)
-{
-       if (!CG(active_op_array)->uses_globals
-               && varname->op_type == IS_CONST
-               && varname->u.constant.type == IS_STRING
-               && varname->u.constant.value.str.len == (sizeof("GLOBALS")-1)
-               && !memcmp(varname->u.constant.value.str.val, "GLOBALS", sizeof("GLOBALS")-1)) {
-               CG(active_op_array)->uses_globals = 1;
-       }
-}
-
 void fetch_simple_variable_ex(znode *result, znode *varname, int bp, int op TSRMLS_DC)
 {
        zend_op opline;
index 621bd8b5f8c03e3782d9a7bcaca16e3b4367c462..6dfa738d58863ab6c3bcb80da5defc5450f3ee59 100644 (file)
@@ -93,7 +93,6 @@ struct _zend_op_array {
        zend_brk_cont_element *brk_cont_array;
        zend_uint last_brk_cont;
        zend_uint current_brk_cont;
-       zend_bool uses_globals;
 
        /* static variables support */
        HashTable *static_variables;
@@ -227,7 +226,6 @@ void fetch_simple_variable(znode *result, znode *varname, int bp TSRMLS_DC);
 void fetch_simple_variable_ex(znode *result, znode *varname, int bp, int op TSRMLS_DC);
 void zend_do_indirect_references(znode *result, znode *num_references, znode *variable TSRMLS_DC);
 void zend_do_fetch_global_or_static_variable(znode *varname, znode *static_assignment, int fetch_type TSRMLS_DC);
-void zend_do_fetch_globals(znode *varname TSRMLS_DC);
 
 void fetch_array_begin(znode *result, znode *varname, znode *first_dim TSRMLS_DC);
 void fetch_array_dim(znode *result, znode *parent, znode *dim TSRMLS_DC);
index e89038f31e38142bcf154eadba6a6c399c777cab..cc1e07a7cb196fedb225205065a992b14e76f8ce 100644 (file)
@@ -1063,19 +1063,6 @@ ZEND_API void execute(zend_op_array *op_array TSRMLS_DC)
        EX(function_state).function_symbol_table = NULL;
 #endif
        
-       if (op_array->uses_globals) {
-               zval *globals;
-
-               ALLOC_ZVAL(globals);
-               globals->refcount=1;
-               globals->is_ref=1;
-               globals->type = IS_ARRAY;
-               globals->value.ht = &EG(symbol_table);
-               if (zend_hash_add(EG(active_symbol_table), "GLOBALS", sizeof("GLOBALS"), &globals, sizeof(zval *), NULL)==FAILURE) {
-                       FREE_ZVAL(globals);
-               }
-       }
-
        while (1) {
 #ifdef ZEND_WIN32
                if (EG(timed_out)) {
index 8927b37084bde56c3cc41b0377f4b6c01589f8a5..12d28b1789d4a6206d16344ae69d5f0c309b0889 100644 (file)
@@ -135,6 +135,16 @@ void init_executor(TSRMLS_D)
        zend_ptr_stack_init(&EG(argument_stack));
 
        zend_hash_init(&EG(symbol_table), 50, NULL, ZVAL_PTR_DTOR, 0);
+       {
+               zval *globals;
+
+               ALLOC_ZVAL(globals);
+               globals->refcount=1;
+               globals->is_ref=1;
+               globals->type = IS_ARRAY;
+               globals->value.ht = &EG(symbol_table);
+               zend_hash_update(&EG(symbol_table), "GLOBALS", sizeof("GLOBALS"), &globals, sizeof(zval *), NULL);
+       }
        EG(active_symbol_table) = &EG(symbol_table);
        
        zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_activator TSRMLS_CC);
index 49c560c20d535800af52b8a5951a9f074a740716..8d61e973ca0a704bc4ea3da2947fa0a26394301f 100644 (file)
@@ -677,7 +677,7 @@ base_cvar_without_objects:
 reference_variable:
                reference_variable '[' dim_offset ']'   { fetch_array_dim(&$$, &$1, &$3 TSRMLS_CC); }
        |       reference_variable '{' expr '}'         { fetch_string_offset(&$$, &$1, &$3 TSRMLS_CC); }
-       |       compound_variable                       { zend_do_fetch_globals(&$1 TSRMLS_CC); zend_do_begin_variable_parse(TSRMLS_C); fetch_simple_variable(&$$, &$1, 1 TSRMLS_CC); }
+       |       compound_variable                       { zend_do_begin_variable_parse(TSRMLS_C); fetch_simple_variable(&$$, &$1, 1 TSRMLS_CC); }
 ;
        
 
@@ -761,8 +761,8 @@ encaps_list:
 
 
 encaps_var:
-               T_VARIABLE { zend_do_fetch_globals(&$1 TSRMLS_CC); zend_do_begin_variable_parse(TSRMLS_C); fetch_simple_variable(&$$, &$1, 1 TSRMLS_CC); }
-       |       T_VARIABLE '[' { zend_do_begin_variable_parse(TSRMLS_C); } encaps_var_offset ']'        { zend_do_fetch_globals(&$1 TSRMLS_CC);  fetch_array_begin(&$$, &$1, &$4 TSRMLS_CC); }
+               T_VARIABLE { zend_do_begin_variable_parse(TSRMLS_C); fetch_simple_variable(&$$, &$1, 1 TSRMLS_CC); }
+       |       T_VARIABLE '[' { zend_do_begin_variable_parse(TSRMLS_C); } encaps_var_offset ']'        { fetch_array_begin(&$$, &$1, &$4 TSRMLS_CC); }
        |       T_VARIABLE T_OBJECT_OPERATOR T_STRING { zend_do_begin_variable_parse(TSRMLS_C); fetch_simple_variable(&$2, &$1, 1 TSRMLS_CC); zend_do_fetch_property(&$$, &$2, &$3 TSRMLS_CC); }
        |       T_DOLLAR_OPEN_CURLY_BRACES expr '}' { zend_do_begin_variable_parse(TSRMLS_C);  fetch_simple_variable(&$$, &$2, 1 TSRMLS_CC); }
        |       T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}' { zend_do_begin_variable_parse(TSRMLS_C);  fetch_array_begin(&$$, &$2, &$4 TSRMLS_CC); }
index b41da55d726e3f8a24374ab71d38b69babe1eb94..d79e0f7b22014f982a7b7dd0362c732218f9775e 100644 (file)
@@ -82,8 +82,6 @@ void init_op_array(zend_op_array *op_array, int type, int initial_ops_size TSRML
 
        op_array->static_variables = NULL;
 
-       op_array->uses_globals = 0;
-
        op_array->return_reference = 0;
        op_array->done_pass_two = 0;