From afeaa60eb2cc7dd3c5a52c0f7aa5b404fd4f8e4f Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Fri, 10 Apr 2026 22:05:07 -0400 Subject: [PATCH] Use ReaddirCalc in all readdir implementations to avoid per-entry path construction Co-Authored-By: Claude Opus 4.6 (1M context) --- src/fuse_readdir_cor_getdents.icpp | 9 +++------ src/fuse_readdir_cor_readdir.icpp | 9 +++------ src/fuse_readdir_cosr_getdents.icpp | 9 +++------ src/fuse_readdir_cosr_readdir.icpp | 9 +++------ src/fuse_readdir_seq_getdents.icpp | 9 +++------ src/fuse_readdir_seq_readdir.icpp | 9 +++------ 6 files changed, 18 insertions(+), 36 deletions(-) diff --git a/src/fuse_readdir_cor_getdents.icpp b/src/fuse_readdir_cor_getdents.icpp index 107de2b4..03fb7941 100644 --- a/src/fuse_readdir_cor_getdents.icpp +++ b/src/fuse_readdir_cor_getdents.icpp @@ -43,7 +43,6 @@ _readdir(const fs::path &branch_path_, { int fd; fuse_msgbuf_t *buf; - fs::path rel_filepath; fs::path abs_dirpath; abs_dirpath = branch_path_ / rel_dirpath_; @@ -56,7 +55,7 @@ _readdir(const fs::path &branch_path_, buf = msgbuf_alloc(); DEFER{ msgbuf_free(buf); }; - rel_filepath = rel_dirpath_ / "dummy"; + fs::inode::ReaddirCalc inodecalc(branch_path_,rel_dirpath_); while(true) { ssize_t nread; @@ -80,10 +79,8 @@ _readdir(const fs::path &branch_path_, if(rv == 0) continue; - rel_filepath.replace_filename(d->name); - - d->ino = fs::inode::calc(branch_path_, - rel_filepath, + d->ino = inodecalc.calc(d->name, + namelen, DTTOIF(d->type), d->ino); diff --git a/src/fuse_readdir_cor_readdir.icpp b/src/fuse_readdir_cor_readdir.icpp index ace92696..3c944917 100644 --- a/src/fuse_readdir_cor_readdir.icpp +++ b/src/fuse_readdir_cor_readdir.icpp @@ -57,7 +57,6 @@ _readdir(const fs::path &branch_path_, mutex_t &mutex_) { DIR *dir; - fs::path rel_filepath; fs::path abs_dirpath; abs_dirpath = branch_path_ / rel_dirpath_; @@ -68,7 +67,7 @@ _readdir(const fs::path &branch_path_, return -errno; DEFER{ fs::closedir(dir); }; - rel_filepath = rel_dirpath_ / "dummy"; + fs::inode::ReaddirCalc inodecalc(branch_path_,rel_dirpath_); while(true) { LockGuard lk(mutex_); @@ -89,10 +88,8 @@ _readdir(const fs::path &branch_path_, if(rv == 0) continue; - rel_filepath.replace_filename(de->d_name); - - de->d_ino = fs::inode::calc(branch_path_, - rel_filepath, + de->d_ino = inodecalc.calc(de->d_name, + namelen, DTTOIF(de->d_type), de->d_ino); diff --git a/src/fuse_readdir_cosr_getdents.icpp b/src/fuse_readdir_cosr_getdents.icpp index 891ee0aa..8fd7e89e 100644 --- a/src/fuse_readdir_cosr_getdents.icpp +++ b/src/fuse_readdir_cosr_getdents.icpp @@ -84,13 +84,11 @@ _readdir(std::vector> &dh_futures_, { Err err; HashSet names; - fs::path rel_filepath; fuse_msgbuf_t *buf; buf = msgbuf_alloc(); DEFER { msgbuf_free(buf); }; - rel_filepath = rel_dirpath_ / "dummy"; for(auto &dh_future : dh_futures_) { DirRV dirrv; @@ -101,6 +99,7 @@ _readdir(std::vector> &dh_futures_, if(dirrv.fd < 0) continue; DEFER { fs::close(dirrv.fd); }; + fs::inode::ReaddirCalc inodecalc(*dirrv.branch_path,rel_dirpath_); while(true) { @@ -124,10 +123,8 @@ _readdir(std::vector> &dh_futures_, if(rv == 0) continue; - rel_filepath.replace_filename(d->name); - - d->ino = fs::inode::calc(*dirrv.branch_path, - rel_filepath, + d->ino = inodecalc.calc(d->name, + namelen, DTTOIF(d->type), d->ino); diff --git a/src/fuse_readdir_cosr_readdir.icpp b/src/fuse_readdir_cosr_readdir.icpp index 3a41923d..e8689199 100644 --- a/src/fuse_readdir_cosr_readdir.icpp +++ b/src/fuse_readdir_cosr_readdir.icpp @@ -94,9 +94,7 @@ _readdir(std::vector> &dh_futures_, { Err err; HashSet names; - fs::path rel_filepath; - rel_filepath = rel_dirpath_ / "dummy"; for(auto &dh_future : dh_futures_) { DirRV dirrv; @@ -107,6 +105,7 @@ _readdir(std::vector> &dh_futures_, if(dirrv.dir == NULL) continue; DEFER { fs::closedir(dirrv.dir); }; + fs::inode::ReaddirCalc inodecalc(*dirrv.branch_path,rel_dirpath_); for(dirent *de = fs::readdir(dirrv.dir); de; @@ -121,10 +120,8 @@ _readdir(std::vector> &dh_futures_, if(rv == 0) continue; - rel_filepath.replace_filename(de->d_name); - - de->d_ino = fs::inode::calc(*dirrv.branch_path, - rel_filepath, + de->d_ino = inodecalc.calc(de->d_name, + namelen, DTTOIF(de->d_type), de->d_ino); diff --git a/src/fuse_readdir_seq_getdents.icpp b/src/fuse_readdir_seq_getdents.icpp index 61ee8b69..e190eccf 100644 --- a/src/fuse_readdir_seq_getdents.icpp +++ b/src/fuse_readdir_seq_getdents.icpp @@ -39,7 +39,6 @@ _readdir(const Branches::Ptr &branches_, { Err err; HashSet names; - fs::path rel_filepath; fs::path abs_dirpath; fuse_msgbuf_t *buf; @@ -48,10 +47,10 @@ _readdir(const Branches::Ptr &branches_, buf = msgbuf_alloc(); DEFER { msgbuf_free(buf); }; - rel_filepath = rel_dirpath_ / "dummy"; for(const auto &branch : *branches_) { int fd; + fs::inode::ReaddirCalc inodecalc(branch.path,rel_dirpath_); abs_dirpath = branch.path / rel_dirpath_; @@ -83,10 +82,8 @@ _readdir(const Branches::Ptr &branches_, if(rv == 0) continue; - rel_filepath.replace_filename(d->name); - - d->ino = fs::inode::calc(branch.path, - rel_filepath, + d->ino = inodecalc.calc(d->name, + namelen, DTTOIF(d->type), d->ino); diff --git a/src/fuse_readdir_seq_readdir.icpp b/src/fuse_readdir_seq_readdir.icpp index 0f8d0cdb..4ca4225c 100644 --- a/src/fuse_readdir_seq_readdir.icpp +++ b/src/fuse_readdir_seq_readdir.icpp @@ -52,15 +52,14 @@ _readdir(const Branches::Ptr &branches_, { Err err; HashSet names; - fs::path rel_filepath; fs::path abs_dirpath; fuse_dirents_reset(dirents_); - rel_filepath = rel_dirpath_ / "dummy"; for(const auto &branch : *branches_) { DIR *dh; + fs::inode::ReaddirCalc inodecalc(branch.path,rel_dirpath_); abs_dirpath = branch.path / rel_dirpath_; @@ -84,10 +83,8 @@ _readdir(const Branches::Ptr &branches_, if(rv == 0) continue; - rel_filepath.replace_filename(de->d_name); - - de->d_ino = fs::inode::calc(branch.path, - rel_filepath, + de->d_ino = inodecalc.calc(de->d_name, + namelen, DTTOIF(de->d_type), de->d_ino);