Commit 4eb069c
committed
Don't allocate during default HashSet creation.
The following `HashMap` creation functions don't allocate heap storage for elements.
```
HashMap::new()
HashMap::default()
HashMap::with_hasher()
```
This is good, because it's surprisingly common to create a HashMap and never
use it. So that case should be cheap.
However, `HashSet` does not have the same behaviour. The corresponding creation
functions *do* allocate heap storage for the default number of non-zero
elements (which is 32 slots for 29 elements).
```
HashMap::new()
HashMap::default()
HashMap::with_hasher()
```
This commit gives `HashSet` the same behaviour as `HashMap`, by simply calling
the corresponding `HashMap` functions (something `HashSet` already does for
`with_capacity` and `with_capacity_and_hasher`). It also reformats one existing
`HashSet` construction to use a consistent single-line format.
This speeds up rustc itself by 1.01--1.04x on most of the non-tiny
rustc-benchmarks.1 parent 458f411 commit 4eb069c
2 files changed
+34
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2087 | 2087 | | |
2088 | 2088 | | |
2089 | 2089 | | |
| 2090 | + | |
2090 | 2091 | | |
2091 | 2092 | | |
2092 | 2093 | | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
2093 | 2108 | | |
2094 | 2109 | | |
2095 | 2110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
| |||
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
121 | | - | |
| 119 | + | |
122 | 120 | | |
123 | 121 | | |
124 | 122 | | |
| |||
163 | 161 | | |
164 | 162 | | |
165 | 163 | | |
166 | | - | |
| 164 | + | |
167 | 165 | | |
168 | 166 | | |
169 | 167 | | |
| |||
188 | 186 | | |
189 | 187 | | |
190 | 188 | | |
191 | | - | |
192 | | - | |
193 | | - | |
| 189 | + | |
194 | 190 | | |
195 | 191 | | |
196 | 192 | | |
| |||
667 | 663 | | |
668 | 664 | | |
669 | 665 | | |
670 | | - | |
| 666 | + | |
671 | 667 | | |
672 | 668 | | |
673 | 669 | | |
| |||
1069 | 1065 | | |
1070 | 1066 | | |
1071 | 1067 | | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
1072 | 1083 | | |
1073 | 1084 | | |
1074 | 1085 | | |
| |||
0 commit comments