Commit 54b3bf1
⚡️ Speed up function
* ⚡️ 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>to_camel_case by 128% (#5239)1 parent fd8e12a commit 54b3bf1
1 file changed
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
186 | 187 | | |
187 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
| |||
0 commit comments