@@ -132,32 +132,40 @@ PHP_MSHUTDOWN_FUNCTION(array) /* {{{ */
132
132
}
133
133
/* }}} */
134
134
135
+ static zend_never_inline ZEND_COLD int stable_sort_fallback (Bucket * a , Bucket * b ) {
136
+ if (Z_EXTRA (a -> val ) > Z_EXTRA (b -> val )) {
137
+ return 1 ;
138
+ } else if (Z_EXTRA (a -> val ) < Z_EXTRA (b -> val )) {
139
+ return -1 ;
140
+ } else {
141
+ return 0 ;
142
+ }
143
+ }
144
+
135
145
#define RETURN_STABLE_SORT (a , b , result ) do { \
136
146
int _result = (result); \
137
147
if (EXPECTED(_result)) { \
138
148
return _result; \
139
149
} \
140
- if (Z_EXTRA((a)->val) > Z_EXTRA((b)->val)) { \
141
- return 1; \
142
- } else if (Z_EXTRA((a)->val) < Z_EXTRA((b)->val)) { \
143
- return -1; \
144
- } else { \
145
- return 0; \
146
- } \
150
+ return stable_sort_fallback((a), (b)); \
147
151
} while (0)
148
152
153
+ /* Generate inlined unstable and stable variants, and non-inlined reversed variants. */
149
154
#define DEFINE_SORT_VARIANTS (name ) \
150
- static int php_array_reverse_ ##name##_unstable(Bucket *a, Bucket *b) { \
151
- return php_array_##name##_unstable (a, b) * -1 ; \
155
+ static zend_never_inline int php_array_ ##name##_unstable(Bucket *a, Bucket *b) { \
156
+ return php_array_##name##_unstable_i (a, b); \
152
157
} \
153
- static int php_array_##name(Bucket *a, Bucket *b) { \
154
- RETURN_STABLE_SORT(a, b, php_array_##name##_unstable(a, b)); \
158
+ static zend_never_inline int php_array_##name(Bucket *a, Bucket *b) { \
159
+ RETURN_STABLE_SORT(a, b, php_array_##name##_unstable_i(a, b)); \
160
+ } \
161
+ static zend_never_inline int php_array_reverse_##name##_unstable(Bucket *a, Bucket *b) { \
162
+ return php_array_##name##_unstable(a, b) * -1; \
155
163
} \
156
- static int php_array_reverse_##name(Bucket *a, Bucket *b) { \
164
+ static zend_never_inline int php_array_reverse_##name(Bucket *a, Bucket *b) { \
157
165
RETURN_STABLE_SORT(a, b, php_array_reverse_##name##_unstable(a, b)); \
158
166
} \
159
167
160
- static int php_array_key_compare_unstable (Bucket * f , Bucket * s ) /* {{{ */
168
+ static zend_always_inline int php_array_key_compare_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
161
169
{
162
170
zend_uchar t ;
163
171
zend_long l1 , l2 ;
@@ -196,7 +204,7 @@ static int php_array_key_compare_unstable(Bucket *f, Bucket *s) /* {{{ */
196
204
}
197
205
/* }}} */
198
206
199
- static int php_array_key_compare_numeric_unstable (Bucket * f , Bucket * s ) /* {{{ */
207
+ static zend_always_inline int php_array_key_compare_numeric_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
200
208
{
201
209
if (f -> key == NULL && s -> key == NULL ) {
202
210
return (zend_long )f -> h > (zend_long )s -> h ? 1 : -1 ;
@@ -217,7 +225,7 @@ static int php_array_key_compare_numeric_unstable(Bucket *f, Bucket *s) /* {{{ *
217
225
}
218
226
/* }}} */
219
227
220
- static int php_array_key_compare_string_case_unstable (Bucket * f , Bucket * s ) /* {{{ */
228
+ static zend_always_inline int php_array_key_compare_string_case_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
221
229
{
222
230
const char * s1 , * s2 ;
223
231
size_t l1 , l2 ;
@@ -242,7 +250,7 @@ static int php_array_key_compare_string_case_unstable(Bucket *f, Bucket *s) /* {
242
250
}
243
251
/* }}} */
244
252
245
- static int php_array_key_compare_string_unstable (Bucket * f , Bucket * s ) /* {{{ */
253
+ static zend_always_inline int php_array_key_compare_string_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
246
254
{
247
255
const char * s1 , * s2 ;
248
256
size_t l1 , l2 ;
@@ -316,7 +324,7 @@ static int php_array_reverse_key_compare_string_natural(Bucket *a, Bucket *b) /*
316
324
}
317
325
/* }}} */
318
326
319
- static int php_array_key_compare_string_locale_unstable (Bucket * f , Bucket * s ) /* {{{ */
327
+ static zend_always_inline int php_array_key_compare_string_locale_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
320
328
{
321
329
const char * s1 , * s2 ;
322
330
char buf1 [MAX_LENGTH_OF_LONG + 1 ];
@@ -336,7 +344,7 @@ static int php_array_key_compare_string_locale_unstable(Bucket *f, Bucket *s) /*
336
344
}
337
345
/* }}} */
338
346
339
- static inline int php_array_data_compare_unstable (Bucket * f , Bucket * s ) /* {{{ */
347
+ static zend_always_inline int php_array_data_compare_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
340
348
{
341
349
zval * first = & f -> val ;
342
350
zval * second = & s -> val ;
@@ -351,7 +359,7 @@ static inline int php_array_data_compare_unstable(Bucket *f, Bucket *s) /* {{{ *
351
359
}
352
360
/* }}} */
353
361
354
- static int php_array_data_compare_numeric_unstable (Bucket * f , Bucket * s ) /* {{{ */
362
+ static zend_always_inline int php_array_data_compare_numeric_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
355
363
{
356
364
zval * first = & f -> val ;
357
365
zval * second = & s -> val ;
@@ -367,7 +375,7 @@ static int php_array_data_compare_numeric_unstable(Bucket *f, Bucket *s) /* {{{
367
375
}
368
376
/* }}} */
369
377
370
- static int php_array_data_compare_string_case_unstable (Bucket * f , Bucket * s ) /* {{{ */
378
+ static zend_always_inline int php_array_data_compare_string_case_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
371
379
{
372
380
zval * first = & f -> val ;
373
381
zval * second = & s -> val ;
@@ -383,7 +391,7 @@ static int php_array_data_compare_string_case_unstable(Bucket *f, Bucket *s) /*
383
391
}
384
392
/* }}} */
385
393
386
- static int php_array_data_compare_string_unstable (Bucket * f , Bucket * s ) /* {{{ */
394
+ static zend_always_inline int php_array_data_compare_string_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
387
395
{
388
396
zval * first = & f -> val ;
389
397
zval * second = & s -> val ;
@@ -413,19 +421,19 @@ static int php_array_natural_general_compare(Bucket *f, Bucket *s, int fold_case
413
421
}
414
422
/* }}} */
415
423
416
- static int php_array_natural_compare_unstable (Bucket * a , Bucket * b ) /* {{{ */
424
+ static zend_always_inline int php_array_natural_compare_unstable_i (Bucket * a , Bucket * b ) /* {{{ */
417
425
{
418
426
return php_array_natural_general_compare (a , b , 0 );
419
427
}
420
428
/* }}} */
421
429
422
- static int php_array_natural_case_compare_unstable (Bucket * a , Bucket * b ) /* {{{ */
430
+ static zend_always_inline int php_array_natural_case_compare_unstable_i (Bucket * a , Bucket * b ) /* {{{ */
423
431
{
424
432
return php_array_natural_general_compare (a , b , 1 );
425
433
}
426
434
/* }}} */
427
435
428
- static int php_array_data_compare_string_locale_unstable (Bucket * f , Bucket * s ) /* {{{ */
436
+ static int php_array_data_compare_string_locale_unstable_i (Bucket * f , Bucket * s ) /* {{{ */
429
437
{
430
438
zval * first = & f -> val ;
431
439
zval * second = & s -> val ;
@@ -911,7 +919,7 @@ PHP_FUNCTION(rsort)
911
919
}
912
920
/* }}} */
913
921
914
- static int php_array_user_compare_unstable (Bucket * f , Bucket * s ) /* {{{ */
922
+ static inline int php_array_user_compare_unstable (Bucket * f , Bucket * s ) /* {{{ */
915
923
{
916
924
zval args [2 ];
917
925
zval retval ;
@@ -1021,7 +1029,7 @@ PHP_FUNCTION(uasort)
1021
1029
}
1022
1030
/* }}} */
1023
1031
1024
- static int php_array_user_key_compare_unstable (Bucket * f , Bucket * s ) /* {{{ */
1032
+ static inline int php_array_user_key_compare_unstable (Bucket * f , Bucket * s ) /* {{{ */
1025
1033
{
1026
1034
zval args [2 ];
1027
1035
zval retval ;
0 commit comments