Commit 426f8cb
committed
perf(codegen): reduce checks printing strings (#10341)
Speed up printing strings.
I had wrongly assumed that `bytes.next().unwrap_unchecked()` would skip checks, but it seems it behaves the same as `bytes.next()` - i.e. check iterator is not empty, and only advance if it's not.
Use `assert_unchecked!` instead to inform compiler that there are definitely the required number of bytes remaining in `bytes` iterator before consuming them.
This reduces instruction count considerably, and removes a branch on every byte consumed.
https://godbolt.org/z/TWzfK1eKj
The mysteries of the compiler!1 parent 0370363 commit 426f8cb
1 file changed
+13
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
122 | 124 | | |
123 | 125 | | |
124 | | - | |
| 126 | + | |
| 127 | + | |
125 | 128 | | |
126 | 129 | | |
127 | 130 | | |
| |||
132 | 135 | | |
133 | 136 | | |
134 | 137 | | |
135 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
136 | 143 | | |
137 | 144 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
142 | 148 | | |
143 | 149 | | |
144 | 150 | | |
| |||
0 commit comments