]> granicus.if.org Git - php/commitdiff
Simplified assignment to string offset
authorDmitry Stogov <dmitry@php.net>
Fri, 11 Jan 2008 15:10:50 +0000 (15:10 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 11 Jan 2008 15:10:50 +0000 (15:10 +0000)
Zend/zend_execute.c

index 156c31f5346631879685a48c5c0faaa2a8163ce5..af7a6d1d07f414aba7bf1f6766fcaaa7181756d7 100644 (file)
@@ -669,94 +669,74 @@ static inline void zend_assign_to_string_offset(temp_variable *T, zval *value, i
        }
 
        if (Z_TYPE_P(T->str_offset.str) == IS_STRING) {
-               zval tmp;
-               zval *final_value = value;
 
                if (((int)T->str_offset.offset < 0)) {
                        zend_error(E_WARNING, "Illegal string offset:  %d", T->str_offset.offset);
                        return;
                }
-               if (T->str_offset.offset >= Z_STRLEN_P(T->str_offset.str)) {
-                       zend_uint i;
 
-                       if (Z_STRLEN_P(T->str_offset.str)==0) {
-                               STR_FREE(Z_STRVAL_P(T->str_offset.str));
-                               Z_STRVAL_P(T->str_offset.str) = (char *) emalloc(T->str_offset.offset+1+1);
-                       } else {
-                               Z_STRVAL_P(T->str_offset.str) = (char *) erealloc(Z_STRVAL_P(T->str_offset.str), T->str_offset.offset+1+1);
-                       }
-                       for (i=Z_STRLEN_P(T->str_offset.str); i<T->str_offset.offset; i++) {
-                               Z_STRVAL_P(T->str_offset.str)[i] = ' ';
-                       }
+               if (T->str_offset.offset >= Z_STRLEN_P(T->str_offset.str)) {
+                       Z_STRVAL_P(T->str_offset.str) = (char *) erealloc(Z_STRVAL_P(T->str_offset.str), T->str_offset.offset+1+1);
+                       memset(Z_STRVAL_P(T->str_offset.str) + Z_STRLEN_P(T->str_offset.str),
+                              ' ',
+                              T->str_offset.offset - Z_STRLEN_P(T->str_offset.str));
                        Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset+1] = 0;
                        Z_STRLEN_P(T->str_offset.str) = T->str_offset.offset+1;
                }
 
                if (Z_TYPE_P(value)!=IS_STRING) {
-                       tmp = *value;
-                       if (value_type & (IS_VAR|IS_CV|IS_CONST)) {
+                       zval tmp = *value;
+                       if (value_type != IS_TMP_VAR) {
                                zval_copy_ctor(&tmp);
                        }
                        convert_to_string(&tmp);
-                       final_value = &tmp;
-               }
-
-               Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL_P(final_value)[0];
-
-               if (final_value == &tmp) {
-                       zval_dtor(final_value);
-               } else if (value_type == IS_TMP_VAR) {
-                       /* we can safely free final_value here
-                        * because separation is done only
-                        * in case value_type == IS_VAR */
-                       STR_FREE(Z_STRVAL_P(final_value));
+                       Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL(tmp)[0];
+                       STR_FREE(Z_STRVAL(tmp));
+               } else {
+                       Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL_P(value)[0];
+                       if (value_type == IS_TMP_VAR) {
+                               /* we can safely free final_value here
+                                * because separation is done only
+                                * in case value_type == IS_VAR */
+                               STR_FREE(Z_STRVAL_P(value));
+                       }
                }
                /*
                 * the value of an assignment to a string offset is undefined
                T(result->u.var).var = &T->str_offset.str;
                */
        } else if (Z_TYPE_P(T->str_offset.str) == IS_UNICODE) {
-               zval tmp;
-               zval *final_value = value;
 
                if (((int)T->str_offset.offset < 0)) {
                        zend_error(E_WARNING, "Illegal string offset:  %d", T->str_offset.offset);
                        return;
                }
-               if (T->str_offset.offset >= Z_USTRLEN_P(T->str_offset.str)) {
-                       zend_uint i;
 
-                       if (Z_USTRLEN_P(T->str_offset.str)==0) {
-                               USTR_FREE(Z_USTRVAL_P(T->str_offset.str));
-                               Z_USTRVAL_P(T->str_offset.str) = eumalloc(T->str_offset.offset+1+1);
-                       } else {
-                               Z_USTRVAL_P(T->str_offset.str) = eurealloc(Z_USTRVAL_P(T->str_offset.str), T->str_offset.offset+1+1);
-                       }
-                       for (i=Z_USTRLEN_P(T->str_offset.str); i<T->str_offset.offset; i++) {
-                               Z_USTRVAL_P(T->str_offset.str)[i] = 0x20; /* ' ' */
-                       }
+               if (T->str_offset.offset >= Z_USTRLEN_P(T->str_offset.str)) {
+                       Z_USTRVAL_P(T->str_offset.str) = (char *) eurealloc(Z_USTRVAL_P(T->str_offset.str), T->str_offset.offset+1+1);
+                       u_memset(Z_USTRVAL_P(T->str_offset.str) + Z_USTRLEN_P(T->str_offset.str),
+                              ' ',
+                              T->str_offset.offset - Z_USTRLEN_P(T->str_offset.str));
                        Z_USTRVAL_P(T->str_offset.str)[T->str_offset.offset+1] = 0;
                        Z_USTRLEN_P(T->str_offset.str) = T->str_offset.offset+1;
                }
 
-               if (Z_TYPE_P(value)!=IS_UNICODE) {
-                       tmp = *value;
-                       if (value_type & (IS_VAR|IS_CV|IS_CONST)) {
+               if (Z_TYPE_P(value) != IS_UNICODE) {
+                       zval tmp = *value;
+                       if (value_type != IS_TMP_VAR) {
                                zval_copy_ctor(&tmp);
                        }
                        convert_to_unicode(&tmp);
-                       final_value = &tmp;
-               }
-
-               Z_USTRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_USTRVAL_P(final_value)[0];
-
-               if (final_value == &tmp) {
-                       zval_dtor(final_value);
-               } else if (value_type == IS_TMP_VAR) {
-                       /* we can safely free final_value here
-                        * because separation is done only
-                        * in case value_type == IS_VAR */
-                       USTR_FREE(Z_USTRVAL_P(final_value));
+                       Z_USTRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_USTRVAL(tmp)[0];
+                       USTR_FREE(Z_USTRVAL(tmp));
+               } else {
+                       Z_USTRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_USTRVAL_P(value)[0];
+                       if (value_type == IS_TMP_VAR) {
+                               /* we can safely free final_value here
+                                * because separation is done only
+                                * in case value_type == IS_VAR */
+                               USTR_FREE(Z_USTRVAL_P(value));
+                       }
                }
        }
 }