⚡️ Speed up function `to_camel_case` by 128% (#5239)
* ⚡️ Speed up function `to_camel_case` by 128%
Here's an optimized version of your code. The time-consuming part is the `re.split` operation, used only for splitting on `-` and `_`, which can be replaced with a much faster approach since there are only two possible delimiters. Using `str.replace` is significantly faster for this case, and the generator expression for capitalization is fine, but can be made a tiny bit faster with a list comprehension. All existing comments are preserved.
**Optimizations made:**
- Removed `re.split`, replacing with a much faster combination of `str.replace` and `str.split`.
- Used a list comprehension for joining capitalized words (marginally faster than a generator for `str.join`).
- Preserves exact same return values for all inputs and all original comments.
This should be much faster, especially for large numbers of short strings.
* remove unneeded comment
---------
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>