summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Tiehuis <marctiehuis@gmail.com>2017-03-01 18:01:46 +1300
committerAndrew Gallant <jamslam@gmail.com>2017-03-08 10:17:18 -0500
commit71585f6d476265338e9ee4e924b4f43b02f2d233 (patch)
treecd289c1b1522b67096ab6997056c45c8c98582f1
parent714ae822418e13b1084d377654b3419f22a51866 (diff)
Reduce unnecessary stat calls for max_filesize
-rw-r--r--ignore/src/walk.rs54
1 files changed, 31 insertions, 23 deletions
diff --git a/ignore/src/walk.rs b/ignore/src/walk.rs
index 37d05ed1..a5989d14 100644
--- a/ignore/src/walk.rs
+++ b/ignore/src/walk.rs
@@ -682,9 +682,16 @@ impl Walk {
return false;
}
- let ft = ent.file_type().is_dir();
- skip_path(&self.ig, ent.path(), ft) ||
- skip_filesize(self.max_filesize, ent.path(), &ent.metadata().ok(), ft)
+ let is_dir = ent.file_type().is_dir();
+ let max_size = self.max_filesize;
+ let should_skip_path = skip_path(&self.ig, ent.path(), is_dir);
+ let should_skip_filesize = if !is_dir && max_size.is_some() {
+ skip_filesize(max_size.unwrap(), ent.path(), &ent.metadata().ok())
+ } else {
+ false
+ };
+
+ should_skip_path || should_skip_filesize
}
}
@@ -1128,10 +1135,15 @@ impl Worker {
}
}
let is_dir = dent.file_type().map_or(false, |ft| ft.is_dir());
- if !skip_path(ig, dent.path(), is_dir) &&
- !skip_filesize(self.max_filesize, dent.path(),
- &dent.metadata().ok(), is_dir)
- {
+ let max_size = self.max_filesize;
+ let should_skip_path = skip_path(ig, dent.path(), is_dir);
+ let should_skip_filesize = if !is_dir && max_size.is_some() {
+ skip_filesize(max_size.unwrap(), dent.path(), &dent.metadata().ok())
+ } else {
+ false
+ };
+
+ if !should_skip_path && !should_skip_filesize {
self.queue.push(Message::Work(Work {
dent: dent,
ignore: ig.clone(),
@@ -1278,31 +1290,27 @@ fn check_symlink_loop(
Ok(())
}
+// Before calling this function, make sure that you ensure that is really
+// necessary as the arguments imply a file stat.
fn skip_filesize(
- max_filesize: Option<u64>,
+ max_filesize: u64,
path: &Path,
- ent: &Option<Metadata>,
- is_dir: bool
+ ent: &Option<Metadata>
) -> bool {
- if is_dir {
- return false;
- }
-
let filesize = match *ent {
Some(ref md) => Some(md.len()),
None => None
};
- match (filesize, max_filesize) {
- (Some(fs), Some(m_fs)) => {
- if fs > m_fs {
- debug!("ignoring {}: {} bytes", path.display(), fs);
- true
- } else {
- false
- }
+ if let Some(fs) = filesize {
+ if fs > max_filesize {
+ debug!("ignoring {}: {} bytes", path.display(), fs);
+ true
+ } else {
+ false
}
- _ => false
+ } else {
+ false
}
}