Move cold inline Flag registration helpers out of the header to reduce code size. Moving RuntimeTypeId and ValueOffset out of the header into the implementation file stops them from being duplicated at flag registration sites while keeping flag reads inline. PiperOrigin-RevId: 1005563147
diff --git a/absl/flags/internal/flag.cc b/absl/flags/internal/flag.cc index 0a1dff2..7c47d54 100644 --- a/absl/flags/internal/flag.cc +++ b/absl/flags/internal/flag.cc
@@ -708,5 +708,22 @@ } } // namespace flags_internal + +namespace flags_internal { +const std::type_info* RuntimeTypeId(FlagOpFn op) { + return reinterpret_cast<const std::type_info*>( + op(FlagOp::kRuntimeTypeId, nullptr, nullptr, nullptr)); +} +} // namespace flags_internal + +namespace flags_internal { +ptrdiff_t ValueOffset(FlagOpFn op) { + // This sequence of casts reverses the sequence from + // `flags_internal::FlagOps()` + return static_cast<ptrdiff_t>(reinterpret_cast<intptr_t>( + op(FlagOp::kValueOffset, nullptr, nullptr, nullptr))); +} +} // namespace flags_internal + ABSL_NAMESPACE_END } // namespace absl
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h index 8ef95ab..9caf1f0 100644 --- a/absl/flags/internal/flag.h +++ b/absl/flags/internal/flag.h
@@ -140,20 +140,12 @@ op(FlagOp::kFastTypeId, nullptr, nullptr, nullptr)); } // Returns fast type id corresponding to the value type. -inline const std::type_info* RuntimeTypeId(FlagOpFn op) { - return reinterpret_cast<const std::type_info*>( - op(FlagOp::kRuntimeTypeId, nullptr, nullptr, nullptr)); -} +const std::type_info* RuntimeTypeId(FlagOpFn op); // Returns offset of the field value_ from the field impl_ inside of // absl::Flag<T> data. Given FlagImpl pointer p you can get the // location of the corresponding value as: // reinterpret_cast<char*>(p) + ValueOffset(). -inline ptrdiff_t ValueOffset(FlagOpFn op) { - // This sequence of casts reverses the sequence from - // `flags_internal::FlagOps()` - return static_cast<ptrdiff_t>(reinterpret_cast<intptr_t>( - op(FlagOp::kValueOffset, nullptr, nullptr, nullptr))); -} +ptrdiff_t ValueOffset(FlagOpFn op); // Returns an address of RTTI's typeid(T). template <typename T>