[php-src] PR #13558: Optimize strpbrk()

From: Date: Thu, 29 Feb 2024 16:46:19 +0000
Subject: [php-src] PR #13558: Optimize strpbrk()
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-25201@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/13558 Author: nielsdos strpbrk() can be implemented using strcspn(). As we have an optimized strcspn() implementation, we can do better than a nested for-loop. This is especially beneficial when the second argument contains more than one character. When testing the following PHP code, I compared the run time in ms: ```php $in = str_repeat('a', (int)$argv[1]) . ' '; for ($i = 0; $i < 3000**2; $i++) { strpbrk($in, ' '); } ``` ![image](https://github.com/php/php-src/assets/7771979/74c956f5-c72b-48aa-a80d-9eb4dcc07f20) Similarly, I have a test variant with multiple characters in the second argument: ```php $in = str_repeat('a', (int)$argv[1]) . ' '; for ($i = 0; $i < 3000**2; $i++) { strpbrk($in, 'qwerty '); } ``` ![image](https://github.com/php/php-src/assets/7771979/71d649b1-4e6f-4fcc-af25-20f65164fd1e)

« previous php.git-pulls (#25201) next »