Skip to content

Commit

Permalink
Simplify config.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Schottkyc137 committed Aug 7, 2024
1 parent 80ebb45 commit 892ec09
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions vhdl_lang/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::io::prelude::*;
use std::path::Path;

use fnv::FnvHashMap;
use itertools::Itertools;
use subst::VariableMap;
use toml::{Table, Value};

Expand Down Expand Up @@ -50,7 +51,7 @@ impl LibraryConfig {
};

if is_literal(stripped_pattern) {
let file_path = Path::new(pattern).to_owned();
let file_path = PathBuf::from(pattern);

if file_path.exists() {
result.push(file_path);
Expand Down Expand Up @@ -86,20 +87,8 @@ impl LibraryConfig {
}
}
}
Self::remove_duplicates(result)
}

/// Remove duplicate file names from the result
fn remove_duplicates(file_names: Vec<PathBuf>) -> Vec<PathBuf> {
let mut result = Vec::with_capacity(file_names.len());
let mut fileset = std::collections::HashSet::new();

for file_name in file_names.into_iter() {
if fileset.insert(file_name.clone()) {
result.push(file_name);
}
}
result
// Remove duplicate file names from the result
result.into_iter().unique().collect()
}

/// Returns the name of the library
Expand Down Expand Up @@ -412,15 +401,7 @@ where

/// Returns true if the pattern is a plain file name and not a glob pattern
fn is_literal(pattern: &str) -> bool {
for chr in pattern.chars() {
match chr {
'?' | '*' | '[' => {
return false;
}
_ => {}
}
}
true
!pattern.chars().any(|chr| matches!(&chr, '?' | '*' | '['))
}

#[cfg(test)]
Expand Down

0 comments on commit 892ec09

Please sign in to comment.