Remove condition that's always true (optimization)

This commit is contained in:
cmal 2018-08-09 11:58:09 +02:00
parent 739c2011a7
commit 31479ff23b

View file

@ -84,30 +84,26 @@ impl Section {
let content = read_file(path)?; let content = read_file(path)?;
let mut section = Section::parse(path, &content, config)?; let mut section = Section::parse(path, &content, config)?;
if section.file.name == "_index" { let parent_dir = path.parent().unwrap();
let parent_dir = path.parent().unwrap(); let assets = find_related_assets(parent_dir);
let assets = find_related_assets(parent_dir);
if let Some(ref globset) = config.ignored_content_globset { if let Some(ref globset) = config.ignored_content_globset {
// `find_related_assets` only scans the immediate directory (it is not recursive) so our // `find_related_assets` only scans the immediate directory (it is not recursive) so our
// filtering only needs to work against the file_name component, not the full suffix. If // filtering only needs to work against the file_name component, not the full suffix. If
// `find_related_assets` was changed to also return files in subdirectories, we could // `find_related_assets` was changed to also return files in subdirectories, we could
// use `PathBuf.strip_prefix` to remove the parent directory and then glob-filter // use `PathBuf.strip_prefix` to remove the parent directory and then glob-filter
// against the remaining path. Note that the current behaviour effectively means that // against the remaining path. Note that the current behaviour effectively means that
// the `ignored_content` setting in the config file is limited to single-file glob // the `ignored_content` setting in the config file is limited to single-file glob
// patterns (no "**" patterns). // patterns (no "**" patterns).
section.assets = assets.into_iter() section.assets = assets.into_iter()
.filter(|path| .filter(|path|
match path.file_name() { match path.file_name() {
None => true, None => true,
Some(file) => !globset.is_match(file) Some(file) => !globset.is_match(file)
} }
).collect(); ).collect();
} else {
section.assets = assets;
}
} else { } else {
section.assets = vec![]; section.assets = assets;
} }
Ok(section) Ok(section)