Closed pinfake closed 4 years ago
@pinfake thanks for your contribution.
We would need to add some test case, so we know that all these changes are good, and nobody change it back to "worst version" in the future.
Do you have any test we can add here? I think string 26Mb long is not what we really want here ;-)
Ok, this is the best I could do :) As you may see it's highly dependand on raw computer power, but i think it is fair enough. I mean the whole test suite running with the "fixed" code took 269 ms on my i5. Took 2.67 minutes to fail with the original code.
Hope thats ok, if you thought of a different approach for the test, let me know!. Thanks a lot for your prompt response!
Thanks, @pinfake!
Thank you! @michalbundyra
… copy of the whole string on each iteration of the loop.
Description
When you try to "encodeQuotedPrintable()" of some real BIG string (our test case was 26 Megabytes long), the loop takes forever to end because it is copying the whole thing except the already processed lines on every iteration (the substr thing at the end). We could not even make it end (running for hours). What I've done here is avoiding this copy and just use indexes where appropriate, only taking line chunks every time. My English may not be so good so, hopefully you can understand what I'm talking about in this discussion: https://codereview.stackexchange.com/questions/7220/php-substr-slow, as it is the same exact situation.
The code itself maybe subject to improvements, could have been written better... Hope it helps.
Regards.