Skip to content

Commit 2c3a2da

Browse files
authored
ext/gd: array supplied to user optimisations. (php#18366)
explictly allocate packed arrays when it applies.
1 parent eeaa60f commit 2c3a2da

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

ext/gd/gd.c

+18-13
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,7 @@ PHP_FUNCTION(imagecolorsforindex)
24382438
col = index;
24392439

24402440
if ((col >= 0 && gdImageTrueColor(im)) || (!gdImageTrueColor(im) && col >= 0 && col < gdImageColorsTotal(im))) {
2441-
array_init(return_value);
2441+
array_init_size(return_value, 4);
24422442

24432443
add_assoc_long(return_value,"red", gdImageRed(im,col));
24442444
add_assoc_long(return_value,"green", gdImageGreen(im,col));
@@ -3303,11 +3303,12 @@ PHP_FUNCTION(imagegetclip)
33033303

33043304
gdImageGetClip(im, &x1, &y1, &x2, &y2);
33053305

3306-
array_init(return_value);
3307-
add_next_index_long(return_value, x1);
3308-
add_next_index_long(return_value, y1);
3309-
add_next_index_long(return_value, x2);
3310-
add_next_index_long(return_value, y2);
3306+
array_init_size(return_value, 4);
3307+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
3308+
add_index_long(return_value, 0, x1);
3309+
add_index_long(return_value, 1, y1);
3310+
add_index_long(return_value, 2, x2);
3311+
add_index_long(return_value, 3, y2);
33113312
}
33123313
/* }}} */
33133314

@@ -3398,11 +3399,12 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
33983399
RETURN_FALSE;
33993400
}
34003401

3401-
array_init(return_value);
3402+
array_init_size(return_value, 8);
3403+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
34023404

34033405
/* return array with the text's bounding box */
34043406
for (i = 0; i < 8; i++) {
3405-
add_next_index_long(return_value, brect[i]);
3407+
add_index_long(return_value, i, brect[i]);
34063408
}
34073409
}
34083410
/* }}} */
@@ -4130,7 +4132,8 @@ PHP_FUNCTION(imageaffinematrixget)
41304132
if (res == GD_FALSE) {
41314133
RETURN_FALSE;
41324134
} else {
4133-
array_init(return_value);
4135+
array_init_size(return_value, 6);
4136+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
41344137
for (uint8_t i = 0; i < 6; i++) {
41354138
add_index_double(return_value, i, affine[i]);
41364139
}
@@ -4196,7 +4199,8 @@ PHP_FUNCTION(imageaffinematrixconcat)
41964199
RETURN_FALSE;
41974200
}
41984201

4199-
array_init(return_value);
4202+
array_init_size(return_value, 6);
4203+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
42004204
for (i = 0; i < 6; i++) {
42014205
add_index_double(return_value, i, mr[i]);
42024206
}
@@ -4288,9 +4292,10 @@ PHP_FUNCTION(imageresolution)
42884292
RETURN_TRUE;
42894293
}
42904294

4291-
array_init(return_value);
4292-
add_next_index_long(return_value, gdImageResolutionX(im));
4293-
add_next_index_long(return_value, gdImageResolutionY(im));
4295+
zval imx, imy;
4296+
ZVAL_LONG(&imx, gdImageResolutionX(im));
4297+
ZVAL_LONG(&imy, gdImageResolutionY(im));
4298+
RETURN_ARR(zend_new_pair(&imx, &imy));
42944299
}
42954300
/* }}} */
42964301

0 commit comments

Comments
 (0)