[all-commits] [llvm/llvm-project] 8462cf: [clang][NFC] Declare `CXXBasePaths::isAmbiguous` a...

David Stone via All-commits all-commits at lists.llvm.org
Sat Nov 29 08:49:05 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8462cff40daf40e58d705f5d86d4e91ef6e6294c
      https://github.com/llvm/llvm-project/commit/8462cff40daf40e58d705f5d86d4e91ef6e6294c
  Author: David Stone <davidfromonline at gmail.com>
  Date:   2025-11-29 (Sat, 29 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` (#169944)

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