Skip to content

Commit 9c2a1f5

Browse files
committed
Avoid useless dereferences and separations during paramter passing.
1 parent 6fe75aa commit 9c2a1f5

26 files changed

+131
-134
lines changed

ext/ctype/ctype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static PHP_MINFO_FUNCTION(ctype)
145145
#define CTYPE(iswhat) \
146146
zval *c, tmp; \
147147
ZEND_PARSE_PARAMETERS_START(1, 1); \
148-
Z_PARAM_ZVAL_DEREF(c) \
148+
Z_PARAM_ZVAL(c) \
149149
ZEND_PARSE_PARAMETERS_END(); \
150150
if (Z_TYPE_P(c) == IS_LONG) { \
151151
if (Z_LVAL_P(c) <= 255 && Z_LVAL_P(c) >= 0) { \

ext/curl/multi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ PHP_FUNCTION(curl_multi_exec)
254254

255255
ZEND_PARSE_PARAMETERS_START(2, 2)
256256
Z_PARAM_RESOURCE(z_mh)
257-
Z_PARAM_ZVAL_DEREF_EX(z_still_running, 0, 1)
257+
Z_PARAM_ZVAL_DEREF(z_still_running)
258258
ZEND_PARSE_PARAMETERS_END();
259259

260260
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
@@ -277,9 +277,9 @@ PHP_FUNCTION(curl_multi_exec)
277277
}
278278
}
279279

280-
convert_to_long(z_still_running);
281-
still_running = Z_LVAL_P(z_still_running);
280+
still_running = zval_get_long(z_still_running);
282281
error = curl_multi_perform(mh->multi, &still_running);
282+
zval_ptr_dtor(z_still_running);
283283
ZVAL_LONG(z_still_running, still_running);
284284

285285
SAVE_CURLM_ERROR(mh, error);
@@ -314,7 +314,7 @@ PHP_FUNCTION(curl_multi_getcontent)
314314
}
315315
/* }}} */
316316

317-
/* {{{ proto array curl_multi_info_read(resource mh [, long msgs_in_queue])
317+
/* {{{ proto array curl_multi_info_read(resource mh [, long &msgs_in_queue])
318318
Get information about the current transfers */
319319
PHP_FUNCTION(curl_multi_info_read)
320320
{
@@ -327,7 +327,7 @@ PHP_FUNCTION(curl_multi_info_read)
327327
ZEND_PARSE_PARAMETERS_START(1, 2)
328328
Z_PARAM_RESOURCE(z_mh)
329329
Z_PARAM_OPTIONAL
330-
Z_PARAM_ZVAL_DEREF_EX(zmsgs_in_queue, 0, 1)
330+
Z_PARAM_ZVAL_DEREF(zmsgs_in_queue)
331331
ZEND_PARSE_PARAMETERS_END();
332332

333333
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
@@ -608,7 +608,7 @@ PHP_FUNCTION(curl_multi_setopt)
608608
ZEND_PARSE_PARAMETERS_START(3,3)
609609
Z_PARAM_RESOURCE(z_mh)
610610
Z_PARAM_LONG(options)
611-
Z_PARAM_ZVAL_DEREF(zvalue)
611+
Z_PARAM_ZVAL(zvalue)
612612
ZEND_PARSE_PARAMETERS_END();
613613

614614
if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {

ext/curl/share.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ PHP_FUNCTION(curl_share_setopt)
107107
ZEND_PARSE_PARAMETERS_START(3,3)
108108
Z_PARAM_RESOURCE(zid)
109109
Z_PARAM_LONG(options)
110-
Z_PARAM_ZVAL_DEREF(zvalue)
110+
Z_PARAM_ZVAL(zvalue)
111111
ZEND_PARSE_PARAMETERS_END();
112112

113113
if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(zid), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {

ext/json/json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static PHP_FUNCTION(json_encode)
227227
zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH;
228228

229229
ZEND_PARSE_PARAMETERS_START(1, 3)
230-
Z_PARAM_ZVAL_DEREF(parameter)
230+
Z_PARAM_ZVAL(parameter)
231231
Z_PARAM_OPTIONAL
232232
Z_PARAM_LONG(options)
233233
Z_PARAM_LONG(depth)

ext/pdo/pdo_dbh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ static PHP_METHOD(PDO, setAttribute)
832832

833833
ZEND_PARSE_PARAMETERS_START(2, 2)
834834
Z_PARAM_LONG(attr)
835-
Z_PARAM_ZVAL_DEREF(value)
835+
Z_PARAM_ZVAL(value)
836836
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
837837

838838
PDO_DBH_CLEAR_ERR();

ext/pdo/pdo_stmt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,8 +1377,8 @@ static PHP_METHOD(PDOStatement, fetchAll)
13771377
ZEND_PARSE_PARAMETERS_START(0, 3)
13781378
Z_PARAM_OPTIONAL
13791379
Z_PARAM_LONG(how)
1380-
Z_PARAM_ZVAL_DEREF(arg2)
1381-
Z_PARAM_ZVAL_DEREF(ctor_args)
1380+
Z_PARAM_ZVAL(arg2)
1381+
Z_PARAM_ZVAL(ctor_args)
13821382
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
13831383

13841384
if (!pdo_stmt_verify_mode(stmt, how, 1)) {
@@ -1699,7 +1699,7 @@ static PHP_METHOD(PDOStatement, setAttribute)
16991699

17001700
ZEND_PARSE_PARAMETERS_START(2, 2)
17011701
Z_PARAM_LONG(attr)
1702-
Z_PARAM_ZVAL_DEREF_EX(value, 1, 0)
1702+
Z_PARAM_ZVAL_EX(value, 1, 0)
17031703
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
17041704

17051705
if (!stmt->methods->set_attribute) {

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
522522

523523
ZEND_PARSE_PARAMETERS_START(2, 4)
524524
Z_PARAM_STRING(func_name, func_name_len)
525-
Z_PARAM_ZVAL_DEREF(callback)
525+
Z_PARAM_ZVAL(callback)
526526
Z_PARAM_OPTIONAL
527527
Z_PARAM_LONG(argc)
528528
Z_PARAM_LONG(flags)
@@ -595,8 +595,8 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
595595

596596
ZEND_PARSE_PARAMETERS_START(3, 4)
597597
Z_PARAM_STRING(func_name, func_name_len)
598-
Z_PARAM_ZVAL_DEREF(step_callback)
599-
Z_PARAM_ZVAL_DEREF(fini_callback)
598+
Z_PARAM_ZVAL(step_callback)
599+
Z_PARAM_ZVAL(fini_callback)
600600
Z_PARAM_OPTIONAL
601601
Z_PARAM_LONG(argc)
602602
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
@@ -658,7 +658,7 @@ static PHP_METHOD(SQLite, sqliteCreateCollation)
658658

659659
ZEND_PARSE_PARAMETERS_START(2, 2)
660660
Z_PARAM_STRING(collation_name, collation_name_len)
661-
Z_PARAM_ZVAL_DEREF(callback)
661+
Z_PARAM_ZVAL(callback)
662662
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
663663

664664
dbh = Z_PDO_DBH_P(getThis());

ext/posix/posix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ PHP_FUNCTION(posix_ttyname)
795795
#endif
796796

797797
ZEND_PARSE_PARAMETERS_START(1, 1)
798-
Z_PARAM_ZVAL_DEREF(z_fd)
798+
Z_PARAM_ZVAL(z_fd)
799799
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
800800

801801
switch (Z_TYPE_P(z_fd)) {
@@ -840,7 +840,7 @@ PHP_FUNCTION(posix_isatty)
840840
int fd;
841841

842842
ZEND_PARSE_PARAMETERS_START(1, 1)
843-
Z_PARAM_ZVAL_DEREF(z_fd)
843+
Z_PARAM_ZVAL(z_fd)
844844
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
845845

846846
switch (Z_TYPE_P(z_fd)) {

ext/standard/array.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ PHP_FUNCTION(array_walk)
15131513
Z_PARAM_ARRAY_OR_OBJECT_EX(array, 0, 1)
15141514
Z_PARAM_FUNC(BG(array_walk_fci), BG(array_walk_fci_cache))
15151515
Z_PARAM_OPTIONAL
1516-
Z_PARAM_ZVAL_EX(userdata, 0, 1)
1516+
Z_PARAM_ZVAL(userdata)
15171517
ZEND_PARSE_PARAMETERS_END_EX(
15181518
BG(array_walk_fci) = orig_array_walk_fci;
15191519
BG(array_walk_fci_cache) = orig_array_walk_fci_cache;
@@ -1543,7 +1543,7 @@ PHP_FUNCTION(array_walk_recursive)
15431543
Z_PARAM_ARRAY_OR_OBJECT_EX(array, 0, 1)
15441544
Z_PARAM_FUNC(BG(array_walk_fci), BG(array_walk_fci_cache))
15451545
Z_PARAM_OPTIONAL
1546-
Z_PARAM_ZVAL_DEREF_EX(userdata, 0, 1)
1546+
Z_PARAM_ZVAL(userdata)
15471547
ZEND_PARSE_PARAMETERS_END_EX(
15481548
BG(array_walk_fci) = orig_array_walk_fci;
15491549
BG(array_walk_fci_cache) = orig_array_walk_fci_cache;
@@ -2470,7 +2470,7 @@ PHP_FUNCTION(extract)
24702470
Z_PARAM_ARRAY_EX2(var_array_param, 0, 1, 0)
24712471
Z_PARAM_OPTIONAL
24722472
Z_PARAM_LONG(extract_type)
2473-
Z_PARAM_ZVAL_EX(prefix, 0, 1)
2473+
Z_PARAM_ZVAL(prefix)
24742474
ZEND_PARSE_PARAMETERS_END();
24752475

24762476
extract_refs = (extract_type & EXTR_REFS);
@@ -2711,7 +2711,7 @@ PHP_FUNCTION(array_fill_keys)
27112711

27122712
ZEND_PARSE_PARAMETERS_START(2, 2)
27132713
Z_PARAM_ARRAY(keys)
2714-
Z_PARAM_ZVAL_DEREF(val)
2714+
Z_PARAM_ZVAL(val)
27152715
ZEND_PARSE_PARAMETERS_END();
27162716

27172717
/* Initialize return array */
@@ -2762,10 +2762,10 @@ PHP_FUNCTION(range)
27622762
double step = 1.0;
27632763

27642764
ZEND_PARSE_PARAMETERS_START(2, 3)
2765-
Z_PARAM_ZVAL_DEREF(zlow)
2766-
Z_PARAM_ZVAL_DEREF(zhigh)
2765+
Z_PARAM_ZVAL(zlow)
2766+
Z_PARAM_ZVAL(zhigh)
27672767
Z_PARAM_OPTIONAL
2768-
Z_PARAM_ZVAL_DEREF(zstep)
2768+
Z_PARAM_ZVAL(zstep)
27692769
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
27702770

27712771
if (zstep) {
@@ -3472,7 +3472,7 @@ PHP_FUNCTION(array_splice)
34723472
Z_PARAM_LONG(offset)
34733473
Z_PARAM_OPTIONAL
34743474
Z_PARAM_LONG(length)
3475-
Z_PARAM_ZVAL_DEREF_EX(repl_array, 0, 1)
3475+
Z_PARAM_ZVAL(repl_array)
34763476
ZEND_PARSE_PARAMETERS_END();
34773477

34783478
num_in = zend_hash_num_elements(Z_ARRVAL_P(array));
@@ -4164,9 +4164,9 @@ PHP_FUNCTION(array_column)
41644164

41654165
ZEND_PARSE_PARAMETERS_START(2, 3)
41664166
Z_PARAM_ARRAY_HT(arr_hash)
4167-
Z_PARAM_ZVAL_DEREF_EX(zcolumn, 1, 0)
4167+
Z_PARAM_ZVAL_EX(zcolumn, 1, 0)
41684168
Z_PARAM_OPTIONAL
4169-
Z_PARAM_ZVAL_DEREF_EX(zkey, 1, 0)
4169+
Z_PARAM_ZVAL_EX(zkey, 1, 0)
41704170
ZEND_PARSE_PARAMETERS_END();
41714171

41724172
if ((zcolumn && !array_column_param_helper(zcolumn, "column")) ||
@@ -4297,7 +4297,7 @@ PHP_FUNCTION(array_pad)
42974297
ZEND_PARSE_PARAMETERS_START(3, 3)
42984298
Z_PARAM_ARRAY(input)
42994299
Z_PARAM_LONG(pad_size)
4300-
Z_PARAM_ZVAL_DEREF(pad_value)
4300+
Z_PARAM_ZVAL(pad_value)
43014301
ZEND_PARSE_PARAMETERS_END();
43024302

43034303
/* Do some initial calculations */
@@ -5864,7 +5864,7 @@ PHP_FUNCTION(array_reduce)
58645864
Z_PARAM_ARRAY(input)
58655865
Z_PARAM_FUNC(fci, fci_cache)
58665866
Z_PARAM_OPTIONAL
5867-
Z_PARAM_ZVAL_DEREF(initial)
5867+
Z_PARAM_ZVAL(initial)
58685868
ZEND_PARSE_PARAMETERS_END();
58695869

58705870

ext/standard/assert.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ PHP_FUNCTION(assert)
158158
}
159159

160160
ZEND_PARSE_PARAMETERS_START(1, 2)
161-
Z_PARAM_ZVAL_DEREF(assertion)
161+
Z_PARAM_ZVAL(assertion)
162162
Z_PARAM_OPTIONAL
163-
Z_PARAM_ZVAL_DEREF(description)
163+
Z_PARAM_ZVAL(description)
164164
ZEND_PARSE_PARAMETERS_END();
165165

166166
if (Z_TYPE_P(assertion) == IS_STRING) {
@@ -297,7 +297,7 @@ PHP_FUNCTION(assert_options)
297297
ZEND_PARSE_PARAMETERS_START(1, 2)
298298
Z_PARAM_LONG(what)
299299
Z_PARAM_OPTIONAL
300-
Z_PARAM_ZVAL_DEREF(value)
300+
Z_PARAM_ZVAL(value)
301301
ZEND_PARSE_PARAMETERS_END();
302302

303303
switch (what) {

ext/standard/basic_functions.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4306,12 +4306,12 @@ PHP_FUNCTION(getopt)
43064306
Z_PARAM_STRING(options, options_len)
43074307
Z_PARAM_OPTIONAL
43084308
Z_PARAM_ARRAY(p_longopts)
4309-
Z_PARAM_ZVAL_DEREF_EX(zoptind, 0, 1)
4309+
Z_PARAM_ZVAL_DEREF(zoptind)
43104310
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
43114311

43124312
/* Init zoptind to 1 */
43134313
if (zoptind) {
4314-
zval_dtor(zoptind);
4314+
zval_ptr_dtor(zoptind);
43154315
ZVAL_LONG(zoptind, 1);
43164316
}
43174317

@@ -5278,7 +5278,7 @@ PHP_FUNCTION(highlight_string)
52785278
int old_error_reporting = EG(error_reporting);
52795279

52805280
ZEND_PARSE_PARAMETERS_START(1, 2)
5281-
Z_PARAM_ZVAL_DEREF(expr)
5281+
Z_PARAM_ZVAL(expr)
52825282
Z_PARAM_OPTIONAL
52835283
Z_PARAM_BOOL(i)
52845284
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
@@ -5572,7 +5572,7 @@ PHP_FUNCTION(print_r)
55725572
zend_bool do_return = 0;
55735573

55745574
ZEND_PARSE_PARAMETERS_START(1, 2)
5575-
Z_PARAM_ZVAL_DEREF(var)
5575+
Z_PARAM_ZVAL(var)
55765576
Z_PARAM_OPTIONAL
55775577
Z_PARAM_BOOL(do_return)
55785578
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
@@ -5805,7 +5805,7 @@ PHP_FUNCTION(unregister_tick_function)
58055805
user_tick_function_entry tick_fe;
58065806

58075807
ZEND_PARSE_PARAMETERS_START(1, 1)
5808-
Z_PARAM_ZVAL_DEREF_EX(function, 0, 1)
5808+
Z_PARAM_ZVAL(function)
58095809
ZEND_PARSE_PARAMETERS_END();
58105810

58115811
if (!BG(user_tick_functions)) {

ext/standard/dns.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -808,17 +808,17 @@ PHP_FUNCTION(dns_get_record)
808808
Z_PARAM_STRING(hostname, hostname_len)
809809
Z_PARAM_OPTIONAL
810810
Z_PARAM_LONG(type_param)
811-
Z_PARAM_ZVAL_DEREF_EX(authns, 1, 1)
812-
Z_PARAM_ZVAL_DEREF_EX(addtl, 1, 1)
811+
Z_PARAM_ZVAL_DEREF_EX(authns, 1, 0)
812+
Z_PARAM_ZVAL_DEREF_EX(addtl, 1, 0)
813813
Z_PARAM_BOOL(raw)
814814
ZEND_PARSE_PARAMETERS_END();
815815

816816
if (authns) {
817-
zval_dtor(authns);
817+
zval_ptr_dtor(authns);
818818
array_init(authns);
819819
}
820820
if (addtl) {
821-
zval_dtor(addtl);
821+
zval_ptr_dtor(addtl);
822822
array_init(addtl);
823823
}
824824

@@ -1041,16 +1041,16 @@ PHP_FUNCTION(dns_get_mx)
10411041

10421042
ZEND_PARSE_PARAMETERS_START(2, 3)
10431043
Z_PARAM_STRING(hostname, hostname_len)
1044-
Z_PARAM_ZVAL_DEREF_EX(mx_list, 0, 1)
1044+
Z_PARAM_ZVAL_DEREF(mx_list)
10451045
Z_PARAM_OPTIONAL
1046-
Z_PARAM_ZVAL_DEREF_EX(weight_list, 0, 1)
1046+
Z_PARAM_ZVAL_DEREF(weight_list)
10471047
ZEND_PARSE_PARAMETERS_END();
10481048

1049-
zval_dtor(mx_list);
1049+
zval_ptr_dtor(mx_list);
10501050
array_init(mx_list);
10511051

10521052
if (weight_list) {
1053-
zval_dtor(weight_list);
1053+
zval_ptr_dtor(weight_list);
10541054
array_init(weight_list);
10551055
}
10561056

ext/standard/exec.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ static void php_exec_ex(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
217217
Z_PARAM_STRING(cmd, cmd_len)
218218
Z_PARAM_OPTIONAL
219219
if (!mode) {
220-
Z_PARAM_ZVAL_DEREF_EX(ret_array, 0, 1)
220+
Z_PARAM_ZVAL_DEREF(ret_array)
221221
}
222-
Z_PARAM_ZVAL_DEREF_EX(ret_code, 0, 1)
222+
Z_PARAM_ZVAL_DEREF(ret_code)
223223
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
224224

225225
if (!cmd_len) {
@@ -235,13 +235,16 @@ static void php_exec_ex(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
235235
ret = php_exec(mode, cmd, NULL, return_value);
236236
} else {
237237
if (Z_TYPE_P(ret_array) != IS_ARRAY) {
238-
zval_dtor(ret_array);
238+
zval_ptr_dtor(ret_array);
239239
array_init(ret_array);
240+
} else if (Z_REFCOUNT_P(ret_array) > 1) {
241+
zval_ptr_dtor(ret_array);
242+
ZVAL_ARR(ret_array, zend_array_dup(Z_ARR_P(ret_array)));
240243
}
241244
ret = php_exec(2, cmd, ret_array, return_value);
242245
}
243246
if (ret_code) {
244-
zval_dtor(ret_code);
247+
zval_ptr_dtor(ret_code);
245248
ZVAL_LONG(ret_code, ret);
246249
}
247250
}

0 commit comments

Comments
 (0)