You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use zend_hash_update instead of zend_hash_add.
These are taking a subset of keys from an array with unique keys,
so the result should also have unique keys.
(this is already done for array_map())
Also, speed up array_intersect and array_diff slightly by
using ZEND_HASH_FOREACH macros.
This way, it doesn't need to load the same buckets and array counts
from memory every time (compiler previously couldn't infer they won't change)
```php
<?php
// $n=10000 now takes 0.095 seconds instead of 0.102
function test_bench(int $n) {
$values = range(0,1000);
$other = range(0,1000);
unset($other[500]);
unset($values[400]);
$total = 0;
for ($i = 0; $i < $n; $i++) {
$total += count(array_intersect_key($values, $other));
}
return $total;
}
```
int (*intersect_data_compare_func)(zval*, zval*) =NULL;
4689
4687
zend_boolok;
4690
4688
zval*val, *data;
4691
4689
intreq_args;
4692
4690
char*param_spec;
4691
+
zend_string*key;
4692
+
zend_ulongh;
4693
4693
4694
4694
/* Get the argument count */
4695
4695
argc=ZEND_NUM_ARGS();
@@ -4727,21 +4727,15 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa
4727
4727
4728
4728
array_init(return_value);
4729
4729
4730
-
for (idx=0; idx<Z_ARRVAL(args[0])->nNumUsed; idx++) {
4731
-
p=Z_ARRVAL(args[0])->arData+idx;
4732
-
val=&p->val;
4733
-
if (Z_TYPE_P(val) ==IS_UNDEF) continue;
4734
-
if (UNEXPECTED(Z_TYPE_P(val) ==IS_INDIRECT)) {
4735
-
val=Z_INDIRECT_P(val);
4736
-
if (Z_TYPE_P(val) ==IS_UNDEF) continue;
4737
-
}
4730
+
/* Iterate over keys of the first array (handling possibility of indirects such as in $GLOBALS), to compute keys that are in all of the other arrays. */
0 commit comments