This is an automated email from the ASF dual-hosted git repository.
HuaHuaY pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new e4405dcd52d GH-53730: [C++] Simplify destructor of `ArrowLog` (#53911)
e4405dcd52d is described below
commit e4405dcd52ddc6f060dc5d1eddb026c4be30c7f2
Author: Alexander <[email protected]>
AuthorDate: Mon Oct 19 04:27:14 2026 +0200
GH-53730: [C++] Simplify destructor of `ArrowLog` (#53911)
### Rationale for this change
@ elfring correctly identified in
https://github.com/apache/arrow/issues/53730 that we perform an unnecessary
null check before invoking `delete`.
Calling `delete` on a `nullptr` is completely safe.
### What changes are included in this PR?
This simplifies the destructor of `ArrowLog`.
Additionally:
- explicitly setting the member to `nullptr` in the destructor is
unnecessary
- my static analyzer also noticed that we can replace the
`reinterpret_cast` with a safer `static_cast`
### Are these changes tested?
Yes
### Are there any user-facing changes?
No
### Was AI used for this PR?
In accordance to the [AI generation
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
please disclose below whether and how AI was used in this PR.
**PR code and description written by:**
- [X] Human
- [ ] AI
**Reviewed before submission by:**
- [X] Human
- [X] AI
- [ ] Not reviewed
* GitHub Issue: #53730
Authored-by: Alexander Taepper <[email protected]>
Signed-off-by: Zehua Zou <[email protected]>
---
cpp/src/arrow/util/logging.cc | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/cpp/src/arrow/util/logging.cc b/cpp/src/arrow/util/logging.cc
index 9a61d261ed3..6c7a82ec08d 100644
--- a/cpp/src/arrow/util/logging.cc
+++ b/cpp/src/arrow/util/logging.cc
@@ -255,12 +255,7 @@ std::ostream& ArrowLog::Stream() {
bool ArrowLog::IsEnabled() const { return is_enabled_; }
-ArrowLog::~ArrowLog() {
- if (logging_provider_ != nullptr) {
- delete reinterpret_cast<LoggingProvider*>(logging_provider_);
- logging_provider_ = nullptr;
- }
-}
+ArrowLog::~ArrowLog() { delete
static_cast<LoggingProvider*>(logging_provider_); }
} // namespace util
} // namespace arrow