summaryrefslogtreecommitdiff
path: root/absl/status
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2023-11-08 11:26:49 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-11-08 11:28:23 -0800
commitc79e6b3db81a167de904d979ab820809e42c1f75 (patch)
tree8a546b33b598d69395fac196eaf468fc5e1ed3be /absl/status
parent8c488c44d893e23b043fa081a4e213a3b9441433 (diff)
Use absl::NoDestructor to replace a bespoke optimized implementation
PiperOrigin-RevId: 580596792 Change-Id: I2f79c9b719e7e95a181b6641e8da191cf0a4d71a
Diffstat (limited to 'absl/status')
-rw-r--r--absl/status/BUILD.bazel1
-rw-r--r--absl/status/CMakeLists.txt1
-rw-r--r--absl/status/status.cc12
3 files changed, 7 insertions, 7 deletions
diff --git a/absl/status/BUILD.bazel b/absl/status/BUILD.bazel
index 10f05f66..3cf0a5e1 100644
--- a/absl/status/BUILD.bazel
+++ b/absl/status/BUILD.bazel
@@ -53,6 +53,7 @@ cc_library(
"//absl/base:atomic_hook",
"//absl/base:config",
"//absl/base:core_headers",
+ "//absl/base:no_destructor",
"//absl/base:raw_logging_internal",
"//absl/base:strerror",
"//absl/container:inlined_vector",
diff --git a/absl/status/CMakeLists.txt b/absl/status/CMakeLists.txt
index fc4ae507..da789901 100644
--- a/absl/status/CMakeLists.txt
+++ b/absl/status/CMakeLists.txt
@@ -36,6 +36,7 @@ absl_cc_library(
absl::function_ref
absl::inlined_vector
absl::memory
+ absl::no_destructor
absl::optional
absl::raw_logging_internal
absl::span
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)