FlagStateInterface implementors need only support being restored once.

PiperOrigin-RevId: 819030565
Change-Id: I92ac8ce4318f8d2e575c13752e490326030ba583
This commit is contained in:
Sam McCall
2025-10-13 23:47:49 -07:00
committed by Copybara-Service
parent cad60580db
commit e5c6ccbc96
3 changed files with 8 additions and 6 deletions

View File

@@ -58,7 +58,7 @@ class FlagStateInterface {
virtual ~FlagStateInterface();
// Restores the flag originated this object to the saved state.
virtual void Restore() const = 0;
virtual void Restore() && = 0;
};
} // namespace flags_internal

View File

@@ -26,6 +26,7 @@
#include <memory>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#include "absl/base/attributes.h"
@@ -139,8 +140,8 @@ class FlagState : public flags_internal::FlagStateInterface {
friend class FlagImpl;
// Restores the flag to the saved state.
void Restore() const override {
if (!flag_impl_.RestoreState(*this)) return;
void Restore() && override {
if (!std::move(flag_impl_).RestoreState(*this)) return;
ABSL_INTERNAL_LOG(INFO,
absl::StrCat("Restore saved value of ", flag_impl_.Name(),

View File

@@ -19,6 +19,7 @@
#include <atomic>
#include <string>
#include <utility>
#include "absl/base/config.h"
#include "absl/base/no_destructor.h"
@@ -320,9 +321,9 @@ class FlagSaverImpl {
}
// Restores the saved flag states into the flag registry.
void RestoreToRegistry() {
void RestoreToRegistry() && {
for (const auto& flag_state : backup_registry_) {
flag_state->Restore();
std::move(*flag_state).Restore();
}
}
@@ -340,7 +341,7 @@ FlagSaver::FlagSaver() : impl_(new flags_internal::FlagSaverImpl) {
FlagSaver::~FlagSaver() {
if (!impl_) return;
impl_->RestoreToRegistry();
std::move(*impl_).RestoreToRegistry();
delete impl_;
}