Skip to content

Commit 56fc29f

Browse files
authored
Speedup little entry access in maps and fix missing extension workarounds (#747)
1 parent ec13f86 commit 56fc29f

File tree

7 files changed

+36
-55
lines changed

7 files changed

+36
-55
lines changed

czkawka_core/src/bad_extensions.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ static WORKAROUNDS: &[(&str, &str)] = &[
3333
("exe", "bck"),
3434
("exe", "com"),
3535
("exe", "cpl"),
36-
("exe", "cpl"),
3736
("exe", "dll"),
3837
("exe", "dll16"),
3938
("exe", "drv"),
@@ -48,7 +47,6 @@ static WORKAROUNDS: &[(&str, &str)] = &[
4847
("exe", "orig"),
4948
("exe", "signed"),
5049
("exe", "sys"),
51-
("exe", "sys"),
5250
("exe", "tlb"),
5351
("exe", "vxd"),
5452
("exe", "winmd"),
@@ -120,7 +118,7 @@ static WORKAROUNDS: &[(&str, &str)] = &[
120118
("html", "svg"),
121119
("xml", "html"),
122120
// Probably bug in external library
123-
("exe", "doc"), // Not sure whe doc is not recognized
121+
("msi", "doc"), // Not sure whe doc is not recognized
124122
("exe", "xls"), // Not sure whe xls is not recognized
125123
];
126124

@@ -318,9 +316,13 @@ impl BadExtensions {
318316
mem::swap(&mut files_to_check, &mut self.files_to_check);
319317
//// PROGRESS THREAD END
320318

321-
let mut hashmap_workarounds: HashMap<&str, &str> = Default::default();
319+
let mut hashmap_workarounds: HashMap<&str, Vec<&str>> = Default::default();
322320
for (proper, found) in WORKAROUNDS {
323-
hashmap_workarounds.insert(found, proper);
321+
// This should be enabled when items will have only 1 possible workaround items
322+
// if hashmap_workarounds.contains_key(found) {
323+
// panic!("Already have {} key", found);
324+
// }
325+
hashmap_workarounds.entry(found).or_insert_with(Vec::new).push(proper);
324326
}
325327

326328
self.bad_extensions_files = files_to_check
@@ -378,9 +380,12 @@ impl BadExtensions {
378380
}
379381

380382
// Workarounds
381-
if let Some(pre) = hashmap_workarounds.get(current_extension.as_str()) {
382-
if all_available_extensions.contains(pre) {
383-
all_available_extensions.insert(current_extension.as_str());
383+
if let Some(vec_pre) = hashmap_workarounds.get(current_extension.as_str()) {
384+
for pre in vec_pre {
385+
if all_available_extensions.contains(pre) {
386+
all_available_extensions.insert(current_extension.as_str());
387+
break;
388+
}
384389
}
385390
}
386391

@@ -400,7 +405,6 @@ impl BadExtensions {
400405
return Some(None);
401406
} else if current_extension.is_empty() {
402407
if !include_files_without_extension {
403-
println!("Empty extension which is disabled by settings");
404408
return Some(None);
405409
}
406410
} else if all_available_extensions.take(&current_extension.as_str()).is_some() {

czkawka_core/src/big_file.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ impl BigFile {
313313
folders_to_check.extend(segment);
314314
self.text_messages.warnings.extend(warnings);
315315
for (size, fe) in fe_result {
316-
old_map.entry(size).or_insert_with(Vec::new);
317-
old_map.get_mut(&size).unwrap().push(fe);
316+
old_map.entry(size).or_insert_with(Vec::new).push(fe);
318317
}
319318
}
320319
}

czkawka_core/src/duplicate.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -568,16 +568,13 @@ impl DuplicateFinder {
568568
let name = file_entry.path.to_string_lossy().to_string();
569569
if !loaded_hash_map2.contains_key(&name) {
570570
// If loaded data doesn't contains current image info
571-
non_cached_files_to_check.entry(file_entry.size).or_insert_with(Vec::new);
572-
non_cached_files_to_check.get_mut(&file_entry.size).unwrap().push(file_entry.clone());
571+
non_cached_files_to_check.entry(file_entry.size).or_insert_with(Vec::new).push(file_entry.clone());
573572
} else if file_entry.size != loaded_hash_map2.get(&name).unwrap().size || file_entry.modified_date != loaded_hash_map2.get(&name).unwrap().modified_date {
574573
// When size or modification date of image changed, then it is clear that is different image
575-
non_cached_files_to_check.entry(file_entry.size).or_insert_with(Vec::new);
576-
non_cached_files_to_check.get_mut(&file_entry.size).unwrap().push(file_entry.clone());
574+
non_cached_files_to_check.entry(file_entry.size).or_insert_with(Vec::new).push(file_entry.clone());
577575
} else {
578576
// Checking may be omitted when already there is entry with same size and modification date
579-
records_already_cached.entry(file_entry.size).or_insert_with(Vec::new);
580-
records_already_cached.get_mut(&file_entry.size).unwrap().push(file_entry.clone());
577+
records_already_cached.entry(file_entry.size).or_insert_with(Vec::new).push(file_entry.clone());
581578
}
582579
}
583580
}
@@ -602,8 +599,7 @@ impl DuplicateFinder {
602599
}
603600
match hash_calculation(&mut buffer, file_entry, &check_type, 0) {
604601
Ok(hash_string) => {
605-
hashmap_with_hash.entry(hash_string.clone()).or_insert_with(Vec::new);
606-
hashmap_with_hash.get_mut(hash_string.as_str()).unwrap().push(file_entry.clone());
602+
hashmap_with_hash.entry(hash_string.clone()).or_insert_with(Vec::new).push(file_entry.clone());
607603
}
608604
Err(s) => errors.push(s),
609605
}
@@ -624,17 +620,15 @@ impl DuplicateFinder {
624620

625621
// Add data from cache
626622
for (size, vec_file_entry) in &records_already_cached {
627-
pre_checked_map.entry(*size).or_insert_with(Vec::new);
628-
pre_checked_map.get_mut(size).unwrap().append(&mut vec_file_entry.clone());
623+
pre_checked_map.entry(*size).or_insert_with(Vec::new).append(&mut vec_file_entry.clone());
629624
}
630625

631626
// Check results
632627
for (size, hash_map, errors) in &pre_hash_results {
633628
self.text_messages.warnings.append(&mut errors.clone());
634629
for vec_file_entry in hash_map.values() {
635630
if vec_file_entry.len() > 1 {
636-
pre_checked_map.entry(*size).or_insert_with(Vec::new);
637-
pre_checked_map.get_mut(size).unwrap().append(&mut vec_file_entry.clone());
631+
pre_checked_map.entry(*size).or_insert_with(Vec::new).append(&mut vec_file_entry.clone());
638632
}
639633
}
640634
}
@@ -732,16 +726,14 @@ impl DuplicateFinder {
732726
let mut found: bool = false;
733727
for loaded_file_entry in loaded_vec_file_entry {
734728
if file_entry.path == loaded_file_entry.path && file_entry.modified_date == loaded_file_entry.modified_date {
735-
records_already_cached.entry(file_entry.size).or_insert_with(Vec::new);
736-
records_already_cached.get_mut(&file_entry.size).unwrap().push(loaded_file_entry.clone());
729+
records_already_cached.entry(file_entry.size).or_insert_with(Vec::new).push(loaded_file_entry.clone());
737730
found = true;
738731
break;
739732
}
740733
}
741734

742735
if !found {
743-
non_cached_files_to_check.entry(file_entry.size).or_insert_with(Vec::new);
744-
non_cached_files_to_check.get_mut(&file_entry.size).unwrap().push(file_entry);
736+
non_cached_files_to_check.entry(file_entry.size).or_insert_with(Vec::new).push(file_entry);
745737
}
746738
}
747739
}
@@ -768,8 +760,7 @@ impl DuplicateFinder {
768760
match hash_calculation(&mut buffer, &file_entry, &check_type, u64::MAX) {
769761
Ok(hash_string) => {
770762
file_entry.hash = hash_string.clone();
771-
hashmap_with_hash.entry(hash_string.clone()).or_insert_with(Vec::new);
772-
hashmap_with_hash.get_mut(hash_string.as_str()).unwrap().push(file_entry);
763+
hashmap_with_hash.entry(hash_string.clone()).or_insert_with(Vec::new).push(file_entry);
773764
}
774765
Err(s) => errors.push(s),
775766
}
@@ -785,17 +776,15 @@ impl DuplicateFinder {
785776
for (full_size, full_hashmap, _errors) in &mut full_hash_results {
786777
if size == *full_size {
787778
for file_entry in vec_file_entry {
788-
full_hashmap.entry(file_entry.hash.clone()).or_insert_with(Vec::new);
789-
full_hashmap.get_mut(&file_entry.hash).unwrap().push(file_entry);
779+
full_hashmap.entry(file_entry.hash.clone()).or_insert_with(Vec::new).push(file_entry);
790780
}
791781
continue 'main;
792782
}
793783
}
794784
// Size doesn't exists add results to files
795785
let mut temp_hashmap: BTreeMap<String, Vec<FileEntry>> = Default::default();
796786
for file_entry in vec_file_entry {
797-
temp_hashmap.entry(file_entry.hash.clone()).or_insert_with(Vec::new);
798-
temp_hashmap.get_mut(&file_entry.hash).unwrap().push(file_entry);
787+
temp_hashmap.entry(file_entry.hash.clone()).or_insert_with(Vec::new).push(file_entry);
799788
}
800789
full_hash_results.push((size, temp_hashmap, Vec::new()));
801790
}
@@ -830,8 +819,7 @@ impl DuplicateFinder {
830819
self.text_messages.warnings.append(&mut errors);
831820
for (_hash, vec_file_entry) in hash_map {
832821
if vec_file_entry.len() > 1 {
833-
self.files_with_identical_hashes.entry(size).or_insert_with(Vec::new);
834-
self.files_with_identical_hashes.get_mut(&size).unwrap().push(vec_file_entry);
822+
self.files_with_identical_hashes.entry(size).or_insert_with(Vec::new).push(vec_file_entry);
835823
}
836824
}
837825
}
@@ -1374,8 +1362,7 @@ pub fn load_hashes_from_file(text_messages: &mut Messages, delete_outdated_cache
13741362
hash: uuu[3].to_string(),
13751363
symlink_info: None,
13761364
};
1377-
hashmap_loaded_entries.entry(file_entry.size).or_insert_with(Vec::new);
1378-
hashmap_loaded_entries.get_mut(&file_entry.size).unwrap().push(file_entry);
1365+
hashmap_loaded_entries.entry(file_entry.size).or_insert_with(Vec::new).push(file_entry);
13791366
}
13801367
}
13811368

czkawka_core/src/same_music.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,7 @@ impl SameMusic {
552552
get_approximate_conversion(&mut thing);
553553
}
554554
if !thing.is_empty() {
555-
hash_map.entry(thing.clone()).or_insert_with(Vec::new);
556-
hash_map.get_mut(thing.as_str()).unwrap().push(file_entry);
555+
hash_map.entry(thing.clone()).or_insert_with(Vec::new).push(file_entry);
557556
}
558557
}
559558
for (_title, vec_file_entry) in hash_map {
@@ -581,8 +580,7 @@ impl SameMusic {
581580
get_approximate_conversion(&mut thing);
582581
}
583582
if !thing.is_empty() {
584-
hash_map.entry(thing.clone()).or_insert_with(Vec::new);
585-
hash_map.get_mut(thing.as_str()).unwrap().push(file_entry);
583+
hash_map.entry(thing.clone()).or_insert_with(Vec::new).push(file_entry);
586584
}
587585
}
588586
for (_title, vec_file_entry) in hash_map {
@@ -607,8 +605,7 @@ impl SameMusic {
607605
for file_entry in vec_file_entry {
608606
let thing = file_entry.year.to_lowercase().trim().to_string();
609607
if !thing.is_empty() {
610-
hash_map.entry(thing.clone()).or_insert_with(Vec::new);
611-
hash_map.get_mut(thing.as_str()).unwrap().push(file_entry);
608+
hash_map.entry(thing.clone()).or_insert_with(Vec::new).push(file_entry);
612609
}
613610
}
614611
for (_title, vec_file_entry) in hash_map {
@@ -633,8 +630,7 @@ impl SameMusic {
633630
for file_entry in vec_file_entry {
634631
let thing = file_entry.length.to_lowercase().trim().to_string();
635632
if !thing.is_empty() {
636-
hash_map.entry(thing.clone()).or_insert_with(Vec::new);
637-
hash_map.get_mut(thing.as_str()).unwrap().push(file_entry);
633+
hash_map.entry(thing.clone()).or_insert_with(Vec::new).push(file_entry);
638634
}
639635
}
640636
for (_title, vec_file_entry) in hash_map {
@@ -659,8 +655,7 @@ impl SameMusic {
659655
for file_entry in vec_file_entry {
660656
let thing = file_entry.genre.to_lowercase().trim().to_string();
661657
if !thing.is_empty() {
662-
hash_map.entry(thing.clone()).or_insert_with(Vec::new);
663-
hash_map.get_mut(thing.as_str()).unwrap().push(file_entry);
658+
hash_map.entry(thing.clone()).or_insert_with(Vec::new).push(file_entry);
664659
}
665660
}
666661
for (_title, vec_file_entry) in hash_map {
@@ -686,8 +681,7 @@ impl SameMusic {
686681
if file_entry.bitrate != 0 {
687682
let thing = file_entry.bitrate.to_string();
688683
if !thing.is_empty() {
689-
hash_map.entry(thing.clone()).or_insert_with(Vec::new);
690-
hash_map.get_mut(thing.as_str()).unwrap().push(file_entry);
684+
hash_map.entry(thing.clone()).or_insert_with(Vec::new).push(file_entry);
691685
}
692686
}
693687
}

czkawka_core/src/similar_images.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,7 @@ impl SimilarImages {
631631
for (file_entry, buf) in &vec_file_entry {
632632
// Only use to comparing, non broken hashes(all 0 or 255 hashes means that algorithm fails to decode them because e.g. contains a log of alpha channel)
633633
if !(buf.is_empty() || buf.iter().all(|e| *e == 0) || buf.iter().all(|e| *e == 255)) {
634-
self.image_hashes.entry(buf.clone()).or_insert_with(Vec::<FileEntry>::new);
635-
self.image_hashes.get_mut(buf).unwrap().push(file_entry.clone());
634+
self.image_hashes.entry(buf.clone()).or_insert_with(Vec::<FileEntry>::new).push(file_entry.clone());
636635
}
637636
}
638637

czkawka_gui/src/connect_things/connect_button_delete.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,7 @@ pub fn tree_remove(
503503

504504
model.remove(&iter);
505505

506-
map_with_path_to_delete.entry(path.clone()).or_insert_with(Vec::new);
507-
map_with_path_to_delete.get_mut(path.as_str()).unwrap().push(file_name);
506+
map_with_path_to_delete.entry(path.clone()).or_insert_with(Vec::new).push(file_name);
508507
}
509508

510509
// Delete duplicated entries, and remove real files

czkawka_gui/src/saving_loading.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ impl LoadSaveStruct {
311311
if line.starts_with("--") {
312312
header = line.to_string();
313313
} else if !header.is_empty() {
314-
self.loaded_items.entry(header.clone()).or_insert_with(Vec::new);
315-
self.loaded_items.get_mut(&header).unwrap().push(line.to_string());
314+
self.loaded_items.entry(header.clone()).or_insert_with(Vec::new).push(line.to_string());
316315
} else {
317316
add_text_to_text_view(
318317
text_view_errors,

0 commit comments

Comments
 (0)