Commit 8462cff
authored
To make this change, we have to use `lookup` instead of `operator[]` on
a map. They both return the same thing: a default constructed value. The
difference is that `lookup` default constructs a value and then returns
it, whereas `operator[]` default constructs a value, inserts it into the
map, and then returns a reference to that. Given that we are using a
by-value return, the only way this is different is if a later use of the
map depends on a value being at that key.
The map is a private variable of the class, so the only possible users
are are other member functions. The only other use of the map that cares
about the contents of the map is in `lookupInBases`, and it accesses the
map with `operator[]`. This means that attempting to access the same
element in this function will default construct the value before doing
anything with it, which means it would do the exact thing it needs to do
in the case where we are looking up a non-existent key, therefore no
behavior has changed.
In terms of performance, this would either be a win or neutral. The
benefit is that in some cases, we can avoid a memory allocation just
read the contents of a 32-bit `0`. If a call to `isAmbiguous` is always
followed up with a call to `lookupInBases`, then we allocate the memory
just a little bit later for no difference in performance.
1 parent a09c579 commit 8462cff
File tree
2 files changed
+3
-3
lines changed- clang
- include/clang/AST
- lib/AST
2 files changed
+3
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
| 195 | + | |
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
0 commit comments