Explorar o código

change(vfs): move dentry dtors to hpp

greatbridf hai 1 ano
pai
achega
61cd2982f9
Modificáronse 2 ficheiros con 25 adicións e 23 borrados
  1. 24 2
      include/kernel/vfs.hpp
  2. 1 21
      src/kernel/vfs.cpp

+ 24 - 2
include/kernel/vfs.hpp

@@ -127,12 +127,34 @@ public:
         explicit dentry(dentry* parent, inode* ind, const name_type& name);
         explicit dentry(dentry* parent, inode* ind, name_type&& name);
         dentry(const dentry& val) = delete;
-        dentry(dentry&& val);
+        constexpr dentry(dentry&& val)
+            : children(std::exchange(val.children, nullptr))
+            , idx_children(std::exchange(val.idx_children, nullptr))
+            , parent(std::exchange(val.parent, nullptr))
+            , ind(std::exchange(val.ind, nullptr))
+            , flags { val.flags }
+            , name(std::move(val.name))
+        {
+            if (children) {
+                for (auto& item : *children)
+                    item.parent = this;
+            }
+        }
 
         dentry& operator=(const dentry& val) = delete;
         dentry& operator=(dentry&& val) = delete;
 
-        ~dentry();
+        constexpr ~dentry()
+        {
+            if (children) {
+                types::pdelete<allocator_type>(children);
+                children = nullptr;
+            }
+            if (idx_children) {
+                types::pdelete<allocator_type>(idx_children);
+                idx_children = nullptr;
+            }
+        }
 
         dentry* append(inode* ind, const name_type& name, bool set_dirty);
         dentry* append(inode* ind, name_type&& name, bool set_dirty);

+ 1 - 21
src/kernel/vfs.cpp

@@ -48,27 +48,7 @@ fs::vfs::dentry::dentry(dentry* _parent, inode* _ind, name_type&& _name)
         idx_children = types::pnew<allocator_type>(idx_children);
     }
 }
-fs::vfs::dentry::dentry(dentry&& val)
-    : children(val.children)
-    , idx_children(val.idx_children)
-    , parent(val.parent)
-    , ind(val.ind)
-    , flags { val.flags }
-    , name(std::move(val.name))
-{
-    if (children) {
-        for (auto& item : *children)
-            item.parent = this;
-    }
-    memset(&val, 0x00, sizeof(dentry));
-}
-fs::vfs::dentry::~dentry()
-{
-    if (children) {
-        types::pdelete<allocator_type>(children);
-        types::pdelete<allocator_type>(idx_children);
-    }
-}
+
 fs::vfs::dentry* fs::vfs::dentry::append(inode* ind, const name_type& name, bool set_dirty)
 {
     auto iter = children->emplace_back(this, ind, name);