From c7d9e9c09a5cc77092c43eef0780e1e8c39076d0 Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 4 May 2022 12:37:07 +0000 Subject: ripple/fossil/mount: don't allocate on readdir Change-Id: I319a2de0da0ff71f0f337e5a17ef199f23254b11 --- ripple/fossil/src/bin/mount.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ripple/fossil') diff --git a/ripple/fossil/src/bin/mount.rs b/ripple/fossil/src/bin/mount.rs index ee46b8e..f1bcdde 100644 --- a/ripple/fossil/src/bin/mount.rs +++ b/ripple/fossil/src/bin/mount.rs @@ -388,23 +388,23 @@ impl fuser::Filesystem for Filesystem { } }; - let mut children = vec![ - (ino, fuser::FileType::Directory, "."), - (ino, fuser::FileType::Directory, ".."), - ]; - - for entry in dir.iter() { + let children = dir.iter().map(|entry| { let kind = match entry.node() { memtree::Node::Directory(_) => fuser::FileType::Directory, memtree::Node::File(_) => fuser::FileType::RegularFile, memtree::Node::Link { .. } => fuser::FileType::Symlink, }; - children.push((ino + entry.index as u64 + 1, kind, &entry.name)); - } + (ino + entry.index as u64 + 1, kind, entry.name.as_str()) + }); + + let children = [ + (ino, fuser::FileType::Directory, "."), + (ino, fuser::FileType::Directory, ".."), + ] + .into_iter() + .chain(children); - for (offset, &(ino, kind, name)) in - children.iter().enumerate().skip(offset as usize) - { + for (offset, (ino, kind, name)) in children.enumerate().skip(offset as usize) { if reply.add(ino, (offset + 1) as i64, kind, name) { break; } -- cgit 1.4.1