[all-commits] [llvm/llvm-project] 4088bb: [clang][NFC] Declare `CXXBasePaths::isAmbiguous` a...
David Stone via All-commits
all-commits at lists.llvm.org
Fri Nov 28 09:38:50 PST 2025
Branch: refs/heads/users/davidstone/declare-CXXBasePaths-isAmbiguous-const
Home: https://github.com/llvm/llvm-project
Commit: 4088bbafe1e07171aaef85f67fa52c8f5c53cd47
https://github.com/llvm/llvm-project/commit/4088bbafe1e07171aaef85f67fa52c8f5c53cd47
Author: David Stone <davidfromonline at gmail.com>
Date: 2025-11-28 (Fri, 28 Nov 2025)
Changed paths:
M clang/include/clang/AST/CXXInheritance.h
M clang/lib/AST/CXXInheritance.cpp
Log Message:
-----------
[clang][NFC] Declare `CXXBasePaths::isAmbiguous` as `const`
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.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list