Commit 38595fb
authored
[libc++] Remove a few unnecessary branches from basic_string::find (llvm#137266)
I've recently looked at the assembly for `basic_string::find()` and
realized that there were a few branches I didn't expect. It turns out
that we check for null before calling `__constexpr_memchr` in some
cases, which the compiler doesn't optimize away. This is a really
uncommon case though, so I'm not convinced it makes a ton of sense to
optimize for that.
The second case is where `__pos >= __sz`. There, we can instead check
`__pos > __sz`, which the optimizer is able to remove if `__pos == 0`,
which is also a quite common case (basic_string::find(CharT), without an
explicit size parameter).1 parent 7d98b66 commit 38595fb
1 file changed
+1
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | 135 | | |
138 | 136 | | |
139 | 137 | | |
| |||
250 | 248 | | |
251 | 249 | | |
252 | 250 | | |
253 | | - | |
254 | | - | |
255 | 251 | | |
256 | 252 | | |
257 | 253 | | |
| |||
352 | 348 | | |
353 | 349 | | |
354 | 350 | | |
355 | | - | |
| 351 | + | |
356 | 352 | | |
357 | 353 | | |
358 | 354 | | |
| |||
0 commit comments