Commit 5ff4fad
Optimize CMAllTitle string allocations
Introduced `upperCaseFirstLower` helper function to perform title-casing (first char upper, rest lower) in a single pass.
This avoids the double allocation caused by `UpperCaseFirst(strings.ToLower(w))` which created an intermediate lower-cased string.
The optimization reduces allocations by ~50% (from ~204 to ~104 allocs/op in benchmarks) and improves memory usage by ~18% for CMAllTitle operations.
Applied the optimization to `SingleCaseWord`, `AcronymWord`, `UpperCaseWord` handling in `WordsToFormattedCase`, and `FirstUpperCaseWord.String()`.
Verified with existing tests and `optimization_test.go` (which targets this specific case).
Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>1 parent d6c51f4 commit 5ff4fad
1 file changed
Lines changed: 40 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
117 | 153 | | |
118 | 154 | | |
119 | 155 | | |
| |||
227 | 263 | | |
228 | 264 | | |
229 | 265 | | |
230 | | - | |
| 266 | + | |
231 | 267 | | |
232 | 268 | | |
233 | 269 | | |
| |||
258 | 294 | | |
259 | 295 | | |
260 | 296 | | |
261 | | - | |
| 297 | + | |
262 | 298 | | |
263 | 299 | | |
264 | 300 | | |
| |||
267 | 303 | | |
268 | 304 | | |
269 | 305 | | |
270 | | - | |
| 306 | + | |
271 | 307 | | |
272 | 308 | | |
273 | 309 | | |
| |||
0 commit comments