Decrease memory usage

master
trivernis 5 years ago
parent ea27a8f643
commit 52378b753d

@ -171,18 +171,15 @@ fn decrypt(_opts: &Opts, args: &Decrypt) {
/// Creates a dictionary from an input file and writes it to the output file /// Creates a dictionary from an input file and writes it to the output file
fn create_dictionary(_opts: &Opts, args: &CreateDictionary) { fn create_dictionary(_opts: &Opts, args: &CreateDictionary) {
let input: String = (*args.input).parse().unwrap(); let input: String = (*args.input).parse().unwrap();
let contents = fs::read_to_string(input).expect("Failed to read input file!"); let sp = spinner("Parsing passwords...");
let lines = contents.lines().collect::<Vec<&str>>(); let dictionary: Vec<PassKey>;
let sp = spinner(format!("Parsing {} passwords...", lines.len()).as_str()); {
let pws = get_lines(&input);
let pws: Vec<String> = lines
.par_iter()
.map(|s| -> String { s.parse().unwrap() })
.collect();
sp.message("Removing duplicates".into()); sp.message("Removing duplicates".into());
let passwords = pws.iter().unique().collect_vec(); let passwords = pws.iter().unique().collect_vec();
sp.message("Mapping passwords to keys".into()); sp.message("Mapping passwords to keys".into());
let dictionary = map_to_keys(passwords); dictionary = map_to_keys(passwords);
}
sp.message("Encoding data to lines".into()); sp.message("Encoding data to lines".into());
let dict_lines: Vec<String> = dictionary let dict_lines: Vec<String> = dictionary
.par_iter() .par_iter()
@ -204,6 +201,15 @@ fn create_dictionary(_opts: &Opts, args: &CreateDictionary) {
println!("Finished!"); println!("Finished!");
} }
fn get_lines(filename: &str) -> Vec<String> {
let contents = fs::read_to_string(filename).expect("Failed to read input file!");
let lines = contents.lines().collect::<Vec<&str>>();
lines
.par_iter()
.map(|s| -> String { s.parse().unwrap() })
.collect()
}
/// Creates a new spinner with a given text /// Creates a new spinner with a given text
fn spinner(text: &str) -> Spinner { fn spinner(text: &str) -> Spinner {
Spinner::new(Spinners::Dots2, text.into()) Spinner::new(Spinners::Dots2, text.into())

Loading…
Cancel
Save