blob: 2a1ed53407730337ffcc543d9dc642a8e5e54ab5 [file]
diff --git a/cpp/src/arrow/status.cc b/cpp/src/arrow/status.cc
index a9581cadc9..1b7ee7df62 100644
--- a/cpp/src/arrow/status.cc
+++ b/cpp/src/arrow/status.cc
@@ -17,6 +17,17 @@
namespace arrow {
+const std::string& Status::NoMessage() {
+ static const std::string* no_message = new std::string();
+ return *no_message;
+}
+
+const std::shared_ptr<StatusDetail>& Status::NoDetail() {
+ static const std::shared_ptr<StatusDetail>* no_detail =
+ new std::shared_ptr<StatusDetail>();
+ return *no_detail;
+}
+
Status::Status(StatusCode code, const std::string& msg)
: Status::Status(code, msg, nullptr) {}
diff --git a/cpp/src/arrow/status.h b/cpp/src/arrow/status.h
index 983b61629d..a49a982922 100644
--- a/cpp/src/arrow/status.h
+++ b/cpp/src/arrow/status.h
@@ -330,14 +330,18 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Status
/// \brief Return the specific error message attached to this status.
const std::string& message() const {
- static const std::string no_message = "";
- return ok() ? no_message : state_->msg;
+ if (ARROW_PREDICT_FALSE(state_ != NULLPTR)) {
+ return state_->msg;
+ }
+ return NoMessage();
}
/// \brief Return the status detail attached to this message.
const std::shared_ptr<StatusDetail>& detail() const {
- static std::shared_ptr<StatusDetail> no_detail = NULLPTR;
- return state_ ? state_->detail : no_detail;
+ if (ARROW_PREDICT_FALSE(state_ != NULLPTR)) {
+ return state_->detail;
+ }
+ return NoDetail();
}
const void* debug_state_addr() const { return state_; }
@@ -396,6 +400,8 @@ class ARROW_EXPORT [[nodiscard]] Status : public util::EqualityComparable<Status
delete state_;
state_ = NULLPTR;
}
+ static const std::string& NoMessage();
+ static const std::shared_ptr<StatusDetail>& NoDetail();
void CopyFrom(const Status& s);
inline void MoveFrom(Status& s);
};