mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 12:31:04 +01:00
Always call MemUsage::Collect to collect metrics from a field (#4480)
Previously Collect() was used for types that implemented CollectMemUsage() but otherwise Add() was used. This required the caller to think about the type of the field and know/decide which method to use. Now, the caller always uses Collect() unless they are adding specific byte values, in which case Add is used. Typically then, Add will only be used to implement the CollectMemUsage() function. To do this we require all Collect() methods to be templates so that they all be a single overload set. The Collect on BumpPtrAllocator is converted to a template that checks `std::same_as<llvm::BumpPtrAllocator, T>`.
This commit is contained in:
@@ -71,8 +71,8 @@ auto Tree::Verify() const -> ErrorOr<Success> {
|
||||
|
||||
auto Tree::CollectMemUsage(MemUsage& mem_usage, llvm::StringRef label) const
|
||||
-> void {
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "node_impls_"), node_impls_);
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "imports_"), imports_);
|
||||
mem_usage.Collect(MemUsage::ConcatLabel(label, "node_impls_"), node_impls_);
|
||||
mem_usage.Collect(MemUsage::ConcatLabel(label, "imports_"), imports_);
|
||||
}
|
||||
|
||||
auto Tree::PostorderIterator::MakeRange(NodeId begin, NodeId end)
|
||||
|
||||
Reference in New Issue
Block a user