> On Jul 5, 2024, at 1:11 PM, Claude Pache <claude.pa...@gmail.com> wrote:
>> Le 25 juin 2024 à 16:36, Gina P. Banyard <intern...@gpb.moe> a écrit :
>> https://wiki.php.net/rfc/deprecations_php_8_4
> 
> 
> * About strtok(): An exact replacement of `strtok()` that is reasonably 
> performant may be constructed with a sequence of strspn(...) and strcspn(...) 
> calls; here is an implementation using a generator in order to keep the 
> state: https://3v4l.org/926tC <https://3v4l.org/926tC>
Well your modern_strtok() function is not an _exact_ replacement as it requires 
using a generator and thus forces the restructure of the code that calls 
strtok(). 

So not a drop-in — search-and-replace — replacement for strtok(). But it is a 
reasonable replacement for those who are motivated to do the restructure.

========

Just out a curiosity for the performance of your modern_strtok() function so I 
benchmarked it and found it takes — on rough average — about ~2.5 times as long 
to run compared to when using strtok():

https://3v4l.org/AMECf#v8.3.9 <https://3v4l.org/AMECf#v8.3.9>

That makes yours the fastest alternative I have benchmarked, but significantly 
still slower than strtok().

I was curious to see if I could improve its performance by avoiding the 
generator, but that just made it slightly worse, e.g. taking — on rough average 
— ~2.75 times as long to run as `strtok()`:

https://3v4l.org/ZVS5Md#v8.3.9 <https://3v4l.org/ZVS5Md#v8.3.9>

#fwiw

-Mike

Reply via email to