Performance: Empty string early return for strip_tags#20675
Conversation
|
I don't mind this optimisation, although I wonder if this is the most common case. It will probably worsen performance in most cases. A little off-topic, but are you sure that you want to use |
You mean stripslashes? Here is strip_tags which commonly used to check and shortcircuit in anythin HTML parsing related. |
|
I meant After having read the original bug report, I think it may actually work fine for what you want it to do, but whenever I see people use this function, it raises a red flag for me that there probably exists a better solution. What if a plugin adds this HTML formatting to an empty title: where the actual title would go after the colon. What if the title is a topic about PHP: |
Nice catch. I will report it as it definitely should be considered. Anyway, even if it was a valid use case or legit scenario where tags should be removed, the empty string is certainly the base scenario, so I think that early returning here is a little win, especially for how much allocation is required even for this base case scenario. |
We were commenting in the WordPress repository about a strange condition: when running an empty string check vs. an empty string with
strip_tagsthe underperforming difference was significant, so I decided to take a look into the code to find that there was no early return for this condition.So I believe this could be a nice little upgrade to the function.