From 98eb410c93ad059f9bba1bf43f5bb916fc92a5ea Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 11 Feb 2020 10:47:28 -0800 Subject: Export of internal Abseil changes -- daa829a331a2316713681b5fe7630d1951e0fdec by Gennadiy Rozental : Eliminate Flag's destroy method. The Abseil Flags are never destroyed. The only place where Destroy method was invoked was in some obscure place during flag registration, where we faces with duplicate retired flag registration. Regired Flag destruction is empty anyway. so we can just delete the duplicate object. The FLagImpl::Destroy is never invoked. PiperOrigin-RevId: 294472413 -- 3c159499ccde8ccdd6907b3a1ddb26be7d3f016f by Abseil Team : Internal change. PiperOrigin-RevId: 294401573 -- 25910db425c50d9b9a8f8275af5a67c2935934fd by Shahriar Rouf : Optimize absl::string_view::compare. Motivation: https://godbolt.org/z/Uz8DWV PiperOrigin-RevId: 294286196 GitOrigin-RevId: daa829a331a2316713681b5fe7630d1951e0fdec Change-Id: I818dad27ac5eb61bb7632e01224953cd882803bf --- absl/flags/internal/commandlineflag.h | 3 --- absl/flags/internal/flag.cc | 21 --------------------- absl/flags/internal/flag.h | 5 ----- absl/flags/internal/registry.cc | 21 +++++++++------------ 4 files changed, 9 insertions(+), 41 deletions(-) (limited to 'absl/flags/internal') diff --git a/absl/flags/internal/commandlineflag.h b/absl/flags/internal/commandlineflag.h index 6a0b5fad..4ac50190 100644 --- a/absl/flags/internal/commandlineflag.h +++ b/absl/flags/internal/commandlineflag.h @@ -178,9 +178,6 @@ class CommandLineFlag { public: constexpr CommandLineFlag() = default; - // Virtual destructor - virtual void Destroy() = 0; - // Not copyable/assignable. CommandLineFlag(const CommandLineFlag&) = delete; CommandLineFlag& operator=(const CommandLineFlag&) = delete; diff --git a/absl/flags/internal/flag.cc b/absl/flags/internal/flag.cc index cfc0cf4d..ba70da91 100644 --- a/absl/flags/internal/flag.cc +++ b/absl/flags/internal/flag.cc @@ -120,27 +120,6 @@ absl::Mutex* FlagImpl::DataGuard() const { return reinterpret_cast(&data_guard_); } -void FlagImpl::Destroy() { - { - absl::MutexLock l(DataGuard()); - - // Values are heap allocated for Abseil Flags. - if (value_.dynamic) Delete(op_, value_.dynamic); - - // Release the dynamically allocated default value if any. - if (DefaultKind() == FlagDefaultKind::kDynamicValue) { - Delete(op_, default_src_.dynamic_value); - } - - // If this flag has an assigned callback, release callback data. - if (callback_) delete callback_; - } - - absl::MutexLock l(&flag_mutex_lifetime_guard); - DataGuard()->~Mutex(); - is_data_guard_inited_ = false; -} - void FlagImpl::AssertValidType(const flags_internal::FlagOpFn op) const { // `op` is the unmarshaling operation corresponding to the declaration // visibile at the call site. `op_` is the Flag's defined unmarshalling diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h index c6c4a2f7..ef30a22f 100644 --- a/absl/flags/internal/flag.h +++ b/absl/flags/internal/flag.h @@ -290,9 +290,6 @@ class FlagImpl { default_src_(default_value_gen), data_guard_{} {} - // Forces destruction of the Flag's data. - void Destroy(); - // Constant access methods absl::string_view Name() const; std::string Filename() const; @@ -515,8 +512,6 @@ class Flag final : public flags_internal::CommandLineFlag { private: friend class FlagState; - void Destroy() override { impl_.Destroy(); } - void Read(void* dst) const override { impl_.Read(dst); } FlagOpFn TypeId() const override { return &FlagOps; } diff --git a/absl/flags/internal/registry.cc b/absl/flags/internal/registry.cc index 7889b1f3..2ef16e84 100644 --- a/absl/flags/internal/registry.cc +++ b/absl/flags/internal/registry.cc @@ -57,11 +57,7 @@ namespace flags_internal { class FlagRegistry { public: FlagRegistry() = default; - ~FlagRegistry() { - for (auto& p : flags_) { - p.second->Destroy(); - } - } + ~FlagRegistry() = default; // Store a flag in this registry. Takes ownership of *flag. void RegisterFlag(CommandLineFlag* flag); @@ -113,6 +109,7 @@ class FlagRegistryLock { FlagRegistry* const fr_; }; +void DestroyRetiredFlag(CommandLineFlag* flag); } // namespace void FlagRegistry::RegisterFlag(CommandLineFlag* flag) { @@ -140,8 +137,8 @@ void FlagRegistry::RegisterFlag(CommandLineFlag* flag) { flag->Typename(), "', respectively."), true); } else if (old_flag->IsRetired()) { - // Retired definitions are idempotent. Just keep the old one. - flag->Destroy(); + // Retired flag can just be deleted. + DestroyRetiredFlag(flag); return; } else if (old_flag->Filename() != flag->Filename()) { flags_internal::ReportUsageError( @@ -291,11 +288,6 @@ class RetiredFlagObj final : public flags_internal::CommandLineFlag { : name_(name), op_(ops) {} private: - void Destroy() override { - // Values are heap allocated for Retired Flags. - delete this; - } - absl::string_view Name() const override { return name_; } std::string Filename() const override { return "RETIRED"; } absl::string_view Typename() const override { return ""; } @@ -328,6 +320,11 @@ class RetiredFlagObj final : public flags_internal::CommandLineFlag { const FlagOpFn op_; }; +void DestroyRetiredFlag(flags_internal::CommandLineFlag* flag) { + assert(flag->IsRetired()); + delete static_cast(flag); +} + } // namespace bool Retire(const char* name, FlagOpFn ops) { -- cgit v1.2.3