Commit a50a896
authored
Rollup merge of rust-lang#69050 - nnethercote:micro-optimize-leb128, r=michaelwoerister
Micro-optimize the heck out of LEB128 reading and writing.
This commit makes the following writing improvements:
- Removes the unnecessary `write_to_vec` function.
- Reduces the number of conditions per loop from 2 to 1.
- Avoids a mask and a shift on the final byte.
And the following reading improvements:
- Removes an unnecessary type annotation.
- Fixes a dangerous unchecked slice access. Imagine a slice `[0x80]` --
the current code will read past the end of the slice some number of
bytes. The bounds check at the end will subsequently trigger, unless
something bad (like a crash) happens first. The cost of doing bounds
check in the loop body is negligible.
- Avoids a mask on the final byte.
And the following improvements for both reading and writing:
- Changes `for` to `loop` for the loops, avoiding an unnecessary
condition on each iteration. This also removes the need for
`leb128_size`.
All of these changes give significant perf wins, up to 5%.
r? @michaelwoerister1 file changed
+14
-50
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 1 | | |
30 | 2 | | |
31 | 3 | | |
32 | 4 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
43 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
44 | 12 | | |
45 | 13 | | |
46 | 14 | | |
| |||
57 | 25 | | |
58 | 26 | | |
59 | 27 | | |
60 | | - | |
| 28 | + | |
61 | 29 | | |
62 | 30 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 31 | + | |
| 32 | + | |
66 | 33 | | |
67 | | - | |
68 | 34 | | |
69 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
70 | 39 | | |
71 | 40 | | |
72 | 41 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | 42 | | |
79 | 43 | | |
80 | 44 | | |
| |||
116 | 80 | | |
117 | 81 | | |
118 | 82 | | |
119 | | - | |
| 83 | + | |
120 | 84 | | |
121 | 85 | | |
122 | 86 | | |
| |||
0 commit comments