Skip to content

Commit

Permalink
Avoid useless dereferences and separations during paramter passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Jun 19, 2017
1 parent 6fe75aa commit 9c2a1f5
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 134 deletions.
2 changes: 1 addition & 1 deletion ext/ctype/ctype.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static PHP_MINFO_FUNCTION(ctype)
#define CTYPE(iswhat) \
zval *c, tmp; \
ZEND_PARSE_PARAMETERS_START(1, 1); \
Z_PARAM_ZVAL_DEREF(c) \
Z_PARAM_ZVAL(c) \
ZEND_PARSE_PARAMETERS_END(); \
if (Z_TYPE_P(c) == IS_LONG) { \
if (Z_LVAL_P(c) <= 255 && Z_LVAL_P(c) >= 0) { \
Expand Down
12 changes: 6 additions & 6 deletions ext/curl/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ PHP_FUNCTION(curl_multi_exec)

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_RESOURCE(z_mh)
Z_PARAM_ZVAL_DEREF_EX(z_still_running, 0, 1)
Z_PARAM_ZVAL_DEREF(z_still_running)
ZEND_PARSE_PARAMETERS_END();

if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
Expand All @@ -277,9 +277,9 @@ PHP_FUNCTION(curl_multi_exec)
}
}

convert_to_long(z_still_running);
still_running = Z_LVAL_P(z_still_running);
still_running = zval_get_long(z_still_running);
error = curl_multi_perform(mh->multi, &still_running);
zval_ptr_dtor(z_still_running);
ZVAL_LONG(z_still_running, still_running);

SAVE_CURLM_ERROR(mh, error);
Expand Down Expand Up @@ -314,7 +314,7 @@ PHP_FUNCTION(curl_multi_getcontent)
}
/* }}} */

/* {{{ proto array curl_multi_info_read(resource mh [, long msgs_in_queue])
/* {{{ proto array curl_multi_info_read(resource mh [, long &msgs_in_queue])
Get information about the current transfers */
PHP_FUNCTION(curl_multi_info_read)
{
Expand All @@ -327,7 +327,7 @@ PHP_FUNCTION(curl_multi_info_read)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_RESOURCE(z_mh)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_DEREF_EX(zmsgs_in_queue, 0, 1)
Z_PARAM_ZVAL_DEREF(zmsgs_in_queue)
ZEND_PARSE_PARAMETERS_END();

if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
Expand Down Expand Up @@ -608,7 +608,7 @@ PHP_FUNCTION(curl_multi_setopt)
ZEND_PARSE_PARAMETERS_START(3,3)
Z_PARAM_RESOURCE(z_mh)
Z_PARAM_LONG(options)
Z_PARAM_ZVAL_DEREF(zvalue)
Z_PARAM_ZVAL(zvalue)
ZEND_PARSE_PARAMETERS_END();

if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion ext/curl/share.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ PHP_FUNCTION(curl_share_setopt)
ZEND_PARSE_PARAMETERS_START(3,3)
Z_PARAM_RESOURCE(zid)
Z_PARAM_LONG(options)
Z_PARAM_ZVAL_DEREF(zvalue)
Z_PARAM_ZVAL(zvalue)
ZEND_PARSE_PARAMETERS_END();

if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(zid), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion ext/json/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static PHP_FUNCTION(json_encode)
zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH;

ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_ZVAL_DEREF(parameter)
Z_PARAM_ZVAL(parameter)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(options)
Z_PARAM_LONG(depth)
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ static PHP_METHOD(PDO, setAttribute)

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_LONG(attr)
Z_PARAM_ZVAL_DEREF(value)
Z_PARAM_ZVAL(value)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

PDO_DBH_CLEAR_ERR();
Expand Down
6 changes: 3 additions & 3 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,8 +1377,8 @@ static PHP_METHOD(PDOStatement, fetchAll)
ZEND_PARSE_PARAMETERS_START(0, 3)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(how)
Z_PARAM_ZVAL_DEREF(arg2)
Z_PARAM_ZVAL_DEREF(ctor_args)
Z_PARAM_ZVAL(arg2)
Z_PARAM_ZVAL(ctor_args)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

if (!pdo_stmt_verify_mode(stmt, how, 1)) {
Expand Down Expand Up @@ -1699,7 +1699,7 @@ static PHP_METHOD(PDOStatement, setAttribute)

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_LONG(attr)
Z_PARAM_ZVAL_DEREF_EX(value, 1, 0)
Z_PARAM_ZVAL_EX(value, 1, 0)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

if (!stmt->methods->set_attribute) {
Expand Down
8 changes: 4 additions & 4 deletions ext/pdo_sqlite/sqlite_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)

ZEND_PARSE_PARAMETERS_START(2, 4)
Z_PARAM_STRING(func_name, func_name_len)
Z_PARAM_ZVAL_DEREF(callback)
Z_PARAM_ZVAL(callback)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(argc)
Z_PARAM_LONG(flags)
Expand Down Expand Up @@ -595,8 +595,8 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)

ZEND_PARSE_PARAMETERS_START(3, 4)
Z_PARAM_STRING(func_name, func_name_len)
Z_PARAM_ZVAL_DEREF(step_callback)
Z_PARAM_ZVAL_DEREF(fini_callback)
Z_PARAM_ZVAL(step_callback)
Z_PARAM_ZVAL(fini_callback)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(argc)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
Expand Down Expand Up @@ -658,7 +658,7 @@ static PHP_METHOD(SQLite, sqliteCreateCollation)

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STRING(collation_name, collation_name_len)
Z_PARAM_ZVAL_DEREF(callback)
Z_PARAM_ZVAL(callback)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

dbh = Z_PDO_DBH_P(getThis());
Expand Down
4 changes: 2 additions & 2 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ PHP_FUNCTION(posix_ttyname)
#endif

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ZVAL_DEREF(z_fd)
Z_PARAM_ZVAL(z_fd)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

switch (Z_TYPE_P(z_fd)) {
Expand Down Expand Up @@ -840,7 +840,7 @@ PHP_FUNCTION(posix_isatty)
int fd;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ZVAL_DEREF(z_fd)
Z_PARAM_ZVAL(z_fd)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

switch (Z_TYPE_P(z_fd)) {
Expand Down
24 changes: 12 additions & 12 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ PHP_FUNCTION(array_walk)
Z_PARAM_ARRAY_OR_OBJECT_EX(array, 0, 1)
Z_PARAM_FUNC(BG(array_walk_fci), BG(array_walk_fci_cache))
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_EX(userdata, 0, 1)
Z_PARAM_ZVAL(userdata)
ZEND_PARSE_PARAMETERS_END_EX(
BG(array_walk_fci) = orig_array_walk_fci;
BG(array_walk_fci_cache) = orig_array_walk_fci_cache;
Expand Down Expand Up @@ -1543,7 +1543,7 @@ PHP_FUNCTION(array_walk_recursive)
Z_PARAM_ARRAY_OR_OBJECT_EX(array, 0, 1)
Z_PARAM_FUNC(BG(array_walk_fci), BG(array_walk_fci_cache))
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_DEREF_EX(userdata, 0, 1)
Z_PARAM_ZVAL(userdata)
ZEND_PARSE_PARAMETERS_END_EX(
BG(array_walk_fci) = orig_array_walk_fci;
BG(array_walk_fci_cache) = orig_array_walk_fci_cache;
Expand Down Expand Up @@ -2470,7 +2470,7 @@ PHP_FUNCTION(extract)
Z_PARAM_ARRAY_EX2(var_array_param, 0, 1, 0)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(extract_type)
Z_PARAM_ZVAL_EX(prefix, 0, 1)
Z_PARAM_ZVAL(prefix)
ZEND_PARSE_PARAMETERS_END();

extract_refs = (extract_type & EXTR_REFS);
Expand Down Expand Up @@ -2711,7 +2711,7 @@ PHP_FUNCTION(array_fill_keys)

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_ARRAY(keys)
Z_PARAM_ZVAL_DEREF(val)
Z_PARAM_ZVAL(val)
ZEND_PARSE_PARAMETERS_END();

/* Initialize return array */
Expand Down Expand Up @@ -2762,10 +2762,10 @@ PHP_FUNCTION(range)
double step = 1.0;

ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_ZVAL_DEREF(zlow)
Z_PARAM_ZVAL_DEREF(zhigh)
Z_PARAM_ZVAL(zlow)
Z_PARAM_ZVAL(zhigh)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_DEREF(zstep)
Z_PARAM_ZVAL(zstep)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

if (zstep) {
Expand Down Expand Up @@ -3472,7 +3472,7 @@ PHP_FUNCTION(array_splice)
Z_PARAM_LONG(offset)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(length)
Z_PARAM_ZVAL_DEREF_EX(repl_array, 0, 1)
Z_PARAM_ZVAL(repl_array)
ZEND_PARSE_PARAMETERS_END();

num_in = zend_hash_num_elements(Z_ARRVAL_P(array));
Expand Down Expand Up @@ -4164,9 +4164,9 @@ PHP_FUNCTION(array_column)

ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_ARRAY_HT(arr_hash)
Z_PARAM_ZVAL_DEREF_EX(zcolumn, 1, 0)
Z_PARAM_ZVAL_EX(zcolumn, 1, 0)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_DEREF_EX(zkey, 1, 0)
Z_PARAM_ZVAL_EX(zkey, 1, 0)
ZEND_PARSE_PARAMETERS_END();

if ((zcolumn && !array_column_param_helper(zcolumn, "column")) ||
Expand Down Expand Up @@ -4297,7 +4297,7 @@ PHP_FUNCTION(array_pad)
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_ARRAY(input)
Z_PARAM_LONG(pad_size)
Z_PARAM_ZVAL_DEREF(pad_value)
Z_PARAM_ZVAL(pad_value)
ZEND_PARSE_PARAMETERS_END();

/* Do some initial calculations */
Expand Down Expand Up @@ -5864,7 +5864,7 @@ PHP_FUNCTION(array_reduce)
Z_PARAM_ARRAY(input)
Z_PARAM_FUNC(fci, fci_cache)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_DEREF(initial)
Z_PARAM_ZVAL(initial)
ZEND_PARSE_PARAMETERS_END();


Expand Down
6 changes: 3 additions & 3 deletions ext/standard/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ PHP_FUNCTION(assert)
}

ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL_DEREF(assertion)
Z_PARAM_ZVAL(assertion)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_DEREF(description)
Z_PARAM_ZVAL(description)
ZEND_PARSE_PARAMETERS_END();

if (Z_TYPE_P(assertion) == IS_STRING) {
Expand Down Expand Up @@ -297,7 +297,7 @@ PHP_FUNCTION(assert_options)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_LONG(what)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_DEREF(value)
Z_PARAM_ZVAL(value)
ZEND_PARSE_PARAMETERS_END();

switch (what) {
Expand Down
10 changes: 5 additions & 5 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -4306,12 +4306,12 @@ PHP_FUNCTION(getopt)
Z_PARAM_STRING(options, options_len)
Z_PARAM_OPTIONAL
Z_PARAM_ARRAY(p_longopts)
Z_PARAM_ZVAL_DEREF_EX(zoptind, 0, 1)
Z_PARAM_ZVAL_DEREF(zoptind)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

/* Init zoptind to 1 */
if (zoptind) {
zval_dtor(zoptind);
zval_ptr_dtor(zoptind);
ZVAL_LONG(zoptind, 1);
}

Expand Down Expand Up @@ -5278,7 +5278,7 @@ PHP_FUNCTION(highlight_string)
int old_error_reporting = EG(error_reporting);

ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL_DEREF(expr)
Z_PARAM_ZVAL(expr)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(i)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
Expand Down Expand Up @@ -5572,7 +5572,7 @@ PHP_FUNCTION(print_r)
zend_bool do_return = 0;

ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ZVAL_DEREF(var)
Z_PARAM_ZVAL(var)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(do_return)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
Expand Down Expand Up @@ -5805,7 +5805,7 @@ PHP_FUNCTION(unregister_tick_function)
user_tick_function_entry tick_fe;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ZVAL_DEREF_EX(function, 0, 1)
Z_PARAM_ZVAL(function)
ZEND_PARSE_PARAMETERS_END();

if (!BG(user_tick_functions)) {
Expand Down
16 changes: 8 additions & 8 deletions ext/standard/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,17 +808,17 @@ PHP_FUNCTION(dns_get_record)
Z_PARAM_STRING(hostname, hostname_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(type_param)
Z_PARAM_ZVAL_DEREF_EX(authns, 1, 1)
Z_PARAM_ZVAL_DEREF_EX(addtl, 1, 1)
Z_PARAM_ZVAL_DEREF_EX(authns, 1, 0)
Z_PARAM_ZVAL_DEREF_EX(addtl, 1, 0)
Z_PARAM_BOOL(raw)
ZEND_PARSE_PARAMETERS_END();

if (authns) {
zval_dtor(authns);
zval_ptr_dtor(authns);
array_init(authns);
}
if (addtl) {
zval_dtor(addtl);
zval_ptr_dtor(addtl);
array_init(addtl);
}

Expand Down Expand Up @@ -1041,16 +1041,16 @@ PHP_FUNCTION(dns_get_mx)

ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STRING(hostname, hostname_len)
Z_PARAM_ZVAL_DEREF_EX(mx_list, 0, 1)
Z_PARAM_ZVAL_DEREF(mx_list)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_DEREF_EX(weight_list, 0, 1)
Z_PARAM_ZVAL_DEREF(weight_list)
ZEND_PARSE_PARAMETERS_END();

zval_dtor(mx_list);
zval_ptr_dtor(mx_list);
array_init(mx_list);

if (weight_list) {
zval_dtor(weight_list);
zval_ptr_dtor(weight_list);
array_init(weight_list);
}

Expand Down
11 changes: 7 additions & 4 deletions ext/standard/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ static void php_exec_ex(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
Z_PARAM_STRING(cmd, cmd_len)
Z_PARAM_OPTIONAL
if (!mode) {
Z_PARAM_ZVAL_DEREF_EX(ret_array, 0, 1)
Z_PARAM_ZVAL_DEREF(ret_array)
}
Z_PARAM_ZVAL_DEREF_EX(ret_code, 0, 1)
Z_PARAM_ZVAL_DEREF(ret_code)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

if (!cmd_len) {
Expand All @@ -235,13 +235,16 @@ static void php_exec_ex(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
ret = php_exec(mode, cmd, NULL, return_value);
} else {
if (Z_TYPE_P(ret_array) != IS_ARRAY) {
zval_dtor(ret_array);
zval_ptr_dtor(ret_array);
array_init(ret_array);
} else if (Z_REFCOUNT_P(ret_array) > 1) {
zval_ptr_dtor(ret_array);
ZVAL_ARR(ret_array, zend_array_dup(Z_ARR_P(ret_array)));
}
ret = php_exec(2, cmd, ret_array, return_value);
}
if (ret_code) {
zval_dtor(ret_code);
zval_ptr_dtor(ret_code);
ZVAL_LONG(ret_code, ret);
}
}
Expand Down

0 comments on commit 9c2a1f5

Please sign in to comment.