diff options
author | Derek Mauro <dmauro@google.com> | 2023-11-08 11:26:49 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-11-08 11:28:23 -0800 |
commit | c79e6b3db81a167de904d979ab820809e42c1f75 (patch) | |
tree | 8a546b33b598d69395fac196eaf468fc5e1ed3be /absl/status/status.cc | |
parent | 8c488c44d893e23b043fa081a4e213a3b9441433 (diff) |
Use absl::NoDestructor to replace a bespoke optimized implementation
PiperOrigin-RevId: 580596792
Change-Id: I2f79c9b719e7e95a181b6641e8da191cf0a4d71a
Diffstat (limited to 'absl/status/status.cc')
-rw-r--r-- | absl/status/status.cc | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/absl/status/status.cc b/absl/status/status.cc index 7eb5d66a..7c778ac0 100644 --- a/absl/status/status.cc +++ b/absl/status/status.cc @@ -28,6 +28,7 @@ #include "absl/base/internal/raw_logging.h" #include "absl/base/internal/strerror.h" #include "absl/base/macros.h" +#include "absl/base/no_destructor.h" #include "absl/debugging/stacktrace.h" #include "absl/debugging/symbolize.h" #include "absl/status/internal/status_internal.h" @@ -90,11 +91,8 @@ std::ostream& operator<<(std::ostream& os, StatusCode code) { } const std::string* Status::EmptyString() { - static union EmptyString { - std::string str; - ~EmptyString() {} - } empty = {{}}; - return &empty.str; + static const absl::NoDestructor<std::string> kEmpty; + return kEmpty.get(); } #ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL @@ -102,8 +100,8 @@ constexpr const char Status::kMovedFromString[]; #endif const std::string* Status::MovedFromString() { - static std::string* moved_from_string = new std::string(kMovedFromString); - return moved_from_string; + static const absl::NoDestructor<std::string> kMovedFrom(kMovedFromString); + return kMovedFrom.get(); } Status::Status(absl::StatusCode code, absl::string_view msg) |