diff options
| author | babenko <[email protected]> | 2026-01-02 14:18:16 +0300 |
|---|---|---|
| committer | babenko <[email protected]> | 2026-01-02 14:36:04 +0300 |
| commit | fb0af3c9f59fa0e43b0ada048421c23eae047682 (patch) | |
| tree | a91798652605799a4462f59a65d13f7d1cc47740 /library/cpp/yt/error/error.cpp | |
| parent | 0399c7dbc09b2ae751be89886e857ba3f0972f8e (diff) | |
YT-27061: Make OKFuture constinit
commit_hash:3522ca2def9e06894323c3ac1b5e0e4e83572857
Diffstat (limited to 'library/cpp/yt/error/error.cpp')
| -rw-r--r-- | library/cpp/yt/error/error.cpp | 38 |
1 files changed, 13 insertions, 25 deletions
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<TError>& ApplyWhitelist(std::vector<TError>& 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<TImpl>(*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<const TSimpleException*>(&ex)) { + if (auto* simpleException = dynamic_cast<const TSimpleException*>(&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<TImpl>(std::move(message))) + : TError(std::make_unique<TImpl>(std::move(message))) { Enrich(); } TError::TErrorOr(TErrorCode code, std::string message, TDisableFormat) - : Impl_(std::make_unique<TImpl>(code, std::move(message))) + : TError(std::make_unique<TImpl>(code, std::move(message))) { Enrich(); } TError& TError::operator = (const TError& other) { - if (other.IsOK()) { - Impl_.reset(); - } else { - Impl_ = std::make_unique<TImpl>(*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<TImpl> impl) - : Impl_(std::move(impl)) + : Impl_(impl.release()) { } void TError::MakeMutable() { if (!Impl_) { - Impl_ = std::make_unique<TImpl>(); + Impl_.reset(new TImpl()); } } |
