From fb0af3c9f59fa0e43b0ada048421c23eae047682 Mon Sep 17 00:00:00 2001 From: babenko Date: Fri, 2 Jan 2026 14:18:16 +0300 Subject: YT-27061: Make OKFuture constinit commit_hash:3522ca2def9e06894323c3ac1b5e0e4e83572857 --- library/cpp/yt/error/error.cpp | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'library/cpp/yt/error/error.cpp') diff --git a/library/cpp/yt/error/error.cpp b/library/cpp/yt/error/error.cpp index 1fbea4c8a4f..fa1cae1c839 100644 --- a/library/cpp/yt/error/error.cpp +++ b/library/cpp/yt/error/error.cpp @@ -230,19 +230,17 @@ std::vector& ApplyWhitelist(std::vector& errors, const THashSet< //////////////////////////////////////////////////////////////////////////////// -TError::TErrorOr() = default; +void TError::TImplDeleter::operator()(TImpl* impl) const +{ + delete impl; +} + +//////////////////////////////////////////////////////////////////////////////// TError::~TErrorOr() = default; TError::TErrorOr(const TError& other) -{ - if (!other.IsOK()) { - Impl_ = std::make_unique(*other.Impl_); - } -} - -TError::TErrorOr(TError&& other) noexcept - : Impl_(std::move(other.Impl_)) + : Impl_(other.IsOK() ? nullptr : new TImpl(*other.Impl_)) { } TError::TErrorOr(const TErrorException& errorEx) noexcept @@ -254,7 +252,7 @@ TError::TErrorOr(const TErrorException& errorEx) noexcept TError::TErrorOr(const std::exception& ex) { - if (auto simpleException = dynamic_cast(&ex)) { + if (auto* simpleException = dynamic_cast(&ex)) { *this = TError(NYT::EErrorCode::Generic, TRuntimeFormat{simpleException->GetMessage()}); // NB: clang-14 is incapable of capturing structured binding variables // so we force materialize them via this function call. @@ -284,30 +282,20 @@ TError::TErrorOr(const std::exception& ex) } TError::TErrorOr(std::string message, TDisableFormat) - : Impl_(std::make_unique(std::move(message))) + : TError(std::make_unique(std::move(message))) { Enrich(); } TError::TErrorOr(TErrorCode code, std::string message, TDisableFormat) - : Impl_(std::make_unique(code, std::move(message))) + : TError(std::make_unique(code, std::move(message))) { Enrich(); } TError& TError::operator = (const TError& other) { - if (other.IsOK()) { - Impl_.reset(); - } else { - Impl_ = std::make_unique(*other.Impl_); - } - return *this; -} - -TError& TError::operator = (TError&& other) noexcept -{ - Impl_ = std::move(other.Impl_); + *this = TError(other); return *this; } @@ -674,13 +662,13 @@ void TError::RegisterFromExceptionEnricher(TFromExceptionEnricher enricher) } TError::TErrorOr(std::unique_ptr impl) - : Impl_(std::move(impl)) + : Impl_(impl.release()) { } void TError::MakeMutable() { if (!Impl_) { - Impl_ = std::make_unique(); + Impl_.reset(new TImpl()); } } -- cgit v1.3