From 485873b19b87a7be3d58efe171692328658b09fd Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Fri, 7 Oct 2022 19:56:49 -0500 Subject: [PATCH] Share logic between move constructor/assignment of dir_iter_t The parent commit made the destructor of the DIR* member close it if necessary (i.e. only if it's not null). This means that we can use the same logic in the move constructor (where the source DIR* is null) and for move assignment (where it might not be). No functional change. --- src/wutil.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/wutil.cpp b/src/wutil.cpp index f5c0a9539..f843e3c12 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -181,16 +181,10 @@ dir_iter_t::dir_iter_t(const wcstring &path) { entry_.dirfd_ = dirfd(&*dir_); } -dir_iter_t::dir_iter_t(dir_iter_t &&rhs) { - // Steal the fields; ensure rhs no longer has FILE* and forgets its fd. - this->dir_ = std::move(rhs.dir_); - this->error_ = rhs.error_; - this->entry_ = std::move(rhs.entry_); - rhs.dir_ = nullptr; - rhs.entry_.dirfd_ = -1; -} +dir_iter_t::dir_iter_t(dir_iter_t &&rhs) { *this = std::move(rhs); } dir_iter_t &dir_iter_t::operator=(dir_iter_t &&rhs) { + // Steal the fields; ensure rhs no longer has DIR* and forgets its fd. this->dir_ = std::move(rhs.dir_); this->error_ = rhs.error_; this->entry_ = std::move(rhs.entry_);