Inline StatusRep::AddSourceLocation in status_internal.h StatusRep::AddSourceLocation is a one-line push_back onto source_locations_, but it is defined in status_internal.cc. Every Status error constructor (through MakeStatusRepImpl) and every Status::AddSourceLocation call in status.cc pays a cross-TU call for it, and the compiler cannot fold the first append into the freshly constructed StatusRep. Moves the body into the class definition in status_internal.h so callers can inline it. The body is unchanged, absl::InlinedVector and absl::SourceLocation are already included there, and no new dependencies are added. Behavior is identical. Measured with status_benchmark, -c opt, 10 interleaved ABBA runs against the unmodified library: BM_CreateBad is 16.4% faster, BM_AppendSourceLocation is 22.5% faster, and BM_LongMessageRValueConvenienceFn is 13.9% faster. No guard benchmark regressed. PiperOrigin-RevId: 1011269337
diff --git a/absl/status/internal/status_internal.cc b/absl/status/internal/status_internal.cc index 9ea01ab..e03b66a 100644 --- a/absl/status/internal/status_internal.cc +++ b/absl/status/internal/status_internal.cc
@@ -142,10 +142,6 @@ return absl::MakeSpan(source_locations_); } -void StatusRep::AddSourceLocation(absl::SourceLocation loc) { - source_locations_.push_back(loc); -} - std::string StatusRep::ToString(StatusToStringMode mode) const { std::string text; absl::StrAppend(&text, absl::StatusCodeToString(code()), ": ", message());
diff --git a/absl/status/internal/status_internal.h b/absl/status/internal/status_internal.h index 07a5679..51e6188 100644 --- a/absl/status/internal/status_internal.h +++ b/absl/status/internal/status_internal.h
@@ -118,7 +118,9 @@ const Payloads* absl_nullable payloads() const { return payloads_.get(); } absl::Span<const SourceLocation> GetSourceLocations() const; - void AddSourceLocation(absl::SourceLocation loc); + void AddSourceLocation(absl::SourceLocation loc) { + source_locations_.push_back(loc); + } std::string ToString(StatusToStringMode mode) const;