Redot-Engine / redot-engine

Redot Engine – Multi-platform 2D and 3D game engine
https://redotengine.org/
MIT License
4.78k stars 214 forks source link

[4.3] Optimize `String::replace` methods #866

Closed Spartan322 closed 6 days ago

Spartan322 commented 6 days ago

Performs a single allocation, only when any instances are found, and avoids concatenations and other unnecessary conversions.

(cherry picked from commit cbaec62b0335bc70c7cf7d55651678591bafafd2)


From godotengine/godot#92546 Fixes #861

This is being cherry-picked from godotengine/godot#92546 in order to solve a bug with String::replace which triggers #861 when String::split_float is called because godotengine/godot#95613 changed String::split_float to expect a null terminator which String::replace does not provide on empty returns, (which appears to be a bug) godotengine/godot#97082 had cherry-picked godotengine/godot#92546 without godotengine/godot#95613 or otherwise fixing String::replace's behavior to produce a null terminator character on empty strings. Since it fixes a bug, benefits performance, and shows no signs of breaking unit tests I decided its better to cherry-pick it then try to fix it another way.