[clang][NFC] Declare CXXBasePaths::isAmbiguous as const
#169944
Merged
+3
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To make this change, we have to use
lookupinstead ofoperator[]on a map. They both return the same thing: a default constructed value. The difference is thatlookupdefault constructs a value and then returns it, whereasoperator[]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 withoperator[]. 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 toisAmbiguousis always followed up with a call tolookupInBases, then we allocate the memory just a little bit later for no difference in performance.