mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:41:06 +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:
@@ -373,10 +373,10 @@ auto TokenizedBuffer::AddComment(int32_t indent, int32_t start, int32_t end)
|
||||
|
||||
auto TokenizedBuffer::CollectMemUsage(MemUsage& mem_usage,
|
||||
llvm::StringRef label) const -> void {
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "allocator_"), allocator_);
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "token_infos_"), token_infos_);
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "line_infos_"), line_infos_);
|
||||
mem_usage.Add(MemUsage::ConcatLabel(label, "comments_"), comments_);
|
||||
mem_usage.Collect(MemUsage::ConcatLabel(label, "allocator_"), allocator_);
|
||||
mem_usage.Collect(MemUsage::ConcatLabel(label, "token_infos_"), token_infos_);
|
||||
mem_usage.Collect(MemUsage::ConcatLabel(label, "line_infos_"), line_infos_);
|
||||
mem_usage.Collect(MemUsage::ConcatLabel(label, "comments_"), comments_);
|
||||
}
|
||||
|
||||
auto TokenizedBuffer::SourceBufferDiagnosticConverter::ConvertLoc(
|
||||
|
||||
Reference in New Issue
Block a user