@@ -1233,15 +1233,58 @@ PHP_FUNCTION(min)
1233
1233
}
1234
1234
} else {
1235
1235
/* mixed min ( mixed $value1 , mixed $value2 [, mixed $value3... ] ) */
1236
- zval * min , result ;
1236
+ zval * min ;
1237
1237
uint32_t i ;
1238
1238
1239
1239
min = & args [0 ];
1240
+ zend_long min_lval ;
1241
+ double min_dval ;
1240
1242
1241
- for (i = 1 ; i < argc ; i ++ ) {
1242
- is_smaller_function (& result , & args [i ], min );
1243
- if (Z_TYPE (result ) == IS_TRUE ) {
1244
- min = & args [i ];
1243
+ if (Z_TYPE_P (min ) == IS_LONG ) {
1244
+ min_lval = Z_LVAL_P (min );
1245
+
1246
+ for (i = 1 ; i < argc ; i ++ ) {
1247
+ if (EXPECTED (Z_TYPE (args [i ]) == IS_LONG )) {
1248
+ if (min_lval > Z_LVAL (args [i ])) {
1249
+ min_lval = Z_LVAL (args [i ]);
1250
+ min = & args [i ];
1251
+ }
1252
+ } else if (Z_TYPE (args [i ]) == IS_DOUBLE && (zend_dval_to_lval ((double ) min_lval ) == min_lval )) {
1253
+ /* if min_lval can be exactly represented as a double, go to double dedicated code */
1254
+ min_dval = (double ) min_lval ;
1255
+ goto double_compare ;
1256
+ } else {
1257
+ goto generic_compare ;
1258
+ }
1259
+ }
1260
+
1261
+ RETURN_LONG (min_lval );
1262
+ } else if (Z_TYPE_P (min ) == IS_DOUBLE ) {
1263
+ min_dval = Z_DVAL_P (min );
1264
+
1265
+ for (i = 1 ; i < argc ; i ++ ) {
1266
+ if (EXPECTED (Z_TYPE (args [i ]) == IS_DOUBLE )) {
1267
+ double_compare :
1268
+ if (min_dval > Z_DVAL (args [i ])) {
1269
+ min_dval = Z_DVAL (args [i ]);
1270
+ min = & args [i ];
1271
+ }
1272
+ } else if (Z_TYPE (args [i ]) == IS_LONG && (zend_dval_to_lval ((double ) Z_LVAL (args [i ])) == Z_LVAL (args [i ]))) {
1273
+ /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */
1274
+ if (min_dval > (double )Z_LVAL (args [i ])) {
1275
+ min_dval = (double )Z_LVAL (args [i ]);
1276
+ min = & args [i ];
1277
+ }
1278
+ } else {
1279
+ goto generic_compare ;
1280
+ }
1281
+ }
1282
+ } else {
1283
+ for (i = 1 ; i < argc ; i ++ ) {
1284
+ generic_compare :
1285
+ if (zend_compare (& args [i ], min ) < 0 ) {
1286
+ min = & args [i ];
1287
+ }
1245
1288
}
1246
1289
}
1247
1290
@@ -1279,15 +1322,58 @@ PHP_FUNCTION(max)
1279
1322
}
1280
1323
} else {
1281
1324
/* mixed max ( mixed $value1 , mixed $value2 [, mixed $value3... ] ) */
1282
- zval * max , result ;
1325
+ zval * max ;
1283
1326
uint32_t i ;
1284
1327
1285
1328
max = & args [0 ];
1329
+ zend_long max_lval ;
1330
+ double max_dval ;
1286
1331
1287
- for (i = 1 ; i < argc ; i ++ ) {
1288
- is_smaller_or_equal_function (& result , & args [i ], max );
1289
- if (Z_TYPE (result ) == IS_FALSE ) {
1290
- max = & args [i ];
1332
+ if (Z_TYPE_P (max ) == IS_LONG ) {
1333
+ max_lval = Z_LVAL_P (max );
1334
+
1335
+ for (i = 1 ; i < argc ; i ++ ) {
1336
+ if (EXPECTED (Z_TYPE (args [i ]) == IS_LONG )) {
1337
+ if (max_lval < Z_LVAL (args [i ])) {
1338
+ max_lval = Z_LVAL (args [i ]);
1339
+ max = & args [i ];
1340
+ }
1341
+ } else if (Z_TYPE (args [i ]) == IS_DOUBLE && (zend_dval_to_lval ((double ) max_lval ) == max_lval )) {
1342
+ /* if max_lval can be exactly represented as a double, go to double dedicated code */
1343
+ max_dval = (double ) max_lval ;
1344
+ goto double_compare ;
1345
+ } else {
1346
+ goto generic_compare ;
1347
+ }
1348
+ }
1349
+
1350
+ RETURN_LONG (max_lval );
1351
+ } else if (Z_TYPE_P (max ) == IS_DOUBLE ) {
1352
+ max_dval = Z_DVAL_P (max );
1353
+
1354
+ for (i = 1 ; i < argc ; i ++ ) {
1355
+ if (EXPECTED (Z_TYPE (args [i ]) == IS_DOUBLE )) {
1356
+ double_compare :
1357
+ if (max_dval < Z_DVAL (args [i ])) {
1358
+ max_dval = Z_DVAL (args [i ]);
1359
+ max = & args [i ];
1360
+ }
1361
+ } else if (Z_TYPE (args [i ]) == IS_LONG && (zend_dval_to_lval ((double ) Z_LVAL (args [i ])) == Z_LVAL (args [i ]))) {
1362
+ /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */
1363
+ if (max_dval < (double )Z_LVAL (args [i ])) {
1364
+ max_dval = (double )Z_LVAL (args [i ]);
1365
+ max = & args [i ];
1366
+ }
1367
+ } else {
1368
+ goto generic_compare ;
1369
+ }
1370
+ }
1371
+ } else {
1372
+ for (i = 1 ; i < argc ; i ++ ) {
1373
+ generic_compare :
1374
+ if (zend_compare (& args [i ], max ) > 0 ) {
1375
+ max = & args [i ];
1376
+ }
1291
1377
}
1292
1378
}
1293
1379
0 commit comments