[GIT-PULLS] [php-src] PR #22648: Optimize array_diff() for long values

[email protected] (mehmetcansahin)
Newsgroups php.git-pulls
Message-ID <BrdW98gDtr05fpj9uUhcFLJ732ncuR9VMErfWziYgxo@main.internal.php.net>
Pull Request: https://github.com/php/php-src/pull/22648
Author: mehmetcansahin

## Summary

This adds a fast path for `array_diff()` when all compared values are integers. Instead of converting values to temporary strings, the implementation builds an integer-keyed exclude map and copies values from the first array when they are not present in that map.

Mixed-type inputs still fall back to the existing generic implementation, preserving current comparison behavior.

## Benchmark

```php
$a = range(0, 200000);
$b = range(100000, 300000);

$start = microtime(true);
for ($i = 0; $i < 10; $i++) {
    array_diff($a, $b);
}
printf("%.3fs\n", microtime(true) - $start);
```

Before: ~0.12s, after: ~0.024s (~5x faster).

## Tests

- `make -j8`
- `./sapi/cli/php run-tests.php -n -q ext/standard/tests/array/array_diff*.phpt` (50/50 pass)

The new test covers integer values, negative values, min/max integers, duplicate values, key preservation, string fallback cases, multiple exclude arrays, references, and empty results.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.