Closed SamMousa closed 5 years ago
I'm not sure I understand the motivation for the manually implemented comparison, which is going to be very slow. Can't we use a strpos loop instead? Something along these lines...
$offset = 0;
while (false !== $offset = strpos($str, $deliminter, $offset)) {
// ...
$offset += strlen($delimiter);
}
I wanted to prevent substring copying; didn't think of using strpos
.
It is definitely a better solution that will also create more readable code.
Side note: why would the manual comparison be slow? Because it's implemented in PHP?
Side note: why would the manual comparison be slow? Because it's implemented in PHP?
For two reasons:
This one looks good, so I went ahead and merged it. We can handle other variants in a followup...
The implementation takes care to not use string comparison functions to prevent needless copying of data.. This does make it a little bit harder to read, so might not be worth it.
Todo:
splitStream
splitCallable
Please check the implementation in #66 as well, it reads a lot easier but comes with the cost of having to do a
substr
call for every character in the data instead of only when emitting a value.