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.
This commit is contained in:
Johannes Altmanninger
2022-10-07 19:56:49 -05:00
parent da5d93b4de
commit 485873b19b

View File

@@ -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_);