mirror of
https://github.com/Dangoware/dmp-core.git
synced 2025-04-20 04:02:54 -05:00
Improved performance by reducing reallocations
This commit is contained in:
parent
421ab0c757
commit
f890f1a026
1 changed files with 12 additions and 8 deletions
|
@ -215,11 +215,8 @@ pub struct MusicLibrary {
|
||||||
pub library: Vec<Song>,
|
pub library: Vec<Song>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn normalize(input_string: &String) -> String {
|
pub fn normalize(input_string: &String) {
|
||||||
unidecode(input_string).chars().filter_map(|c: char| {
|
unidecode(input_string).retain(|c| !c.is_whitespace());
|
||||||
let x = c.to_ascii_lowercase();
|
|
||||||
c.is_alphanumeric().then_some(x)
|
|
||||||
}).collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MusicLibrary {
|
impl MusicLibrary {
|
||||||
|
@ -690,7 +687,7 @@ impl MusicLibrary {
|
||||||
|
|
||||||
self.library.par_iter().for_each(|track| {
|
self.library.par_iter().for_each(|track| {
|
||||||
for tag in target_tags {
|
for tag in target_tags {
|
||||||
let track_result = match tag {
|
let mut track_result = match tag {
|
||||||
Tag::Field(target) => match track.get_field(&target) {
|
Tag::Field(target) => match track.get_field(&target) {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => continue,
|
None => continue,
|
||||||
|
@ -701,7 +698,10 @@ impl MusicLibrary {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if normalize(&track_result).contains(&normalize(&query_string)) {
|
normalize(&mut query_string.to_owned());
|
||||||
|
normalize(&mut track_result);
|
||||||
|
|
||||||
|
if track_result.contains(query_string) {
|
||||||
songs.lock().unwrap().push(track);
|
songs.lock().unwrap().push(track);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -772,8 +772,12 @@ impl MusicLibrary {
|
||||||
Some(title) => title,
|
Some(title) => title,
|
||||||
None => continue
|
None => continue
|
||||||
};
|
};
|
||||||
|
normalize(title);
|
||||||
|
|
||||||
match albums.binary_search_by_key(&title, |album| album.title) {
|
match albums.binary_search_by_key(&title, |album| {
|
||||||
|
normalize(&album.title);
|
||||||
|
album.title
|
||||||
|
}) {
|
||||||
Ok(pos) => {
|
Ok(pos) => {
|
||||||
albums[pos].tracks.push(result);
|
albums[pos].tracks.push(result);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue