Change unnecessary usage of Arc to borrow instead

Some basic cleanup of function signatures that took ownership of their
parameters, even though they didn't need ownership. Switching over the
usage of `Arc` to a normal borrow has the added benefit of cleaning up
the code a bit since now a reference can be given instead of having to
clone the values. The other benefit is that a lot of clones aren't
necessary anymore. It's not going to have noticable performance
benefits, but it is still a good thing to have less clones all over the
code.
This commit is contained in:
Thomas Frans
2023-03-05 00:02:25 +01:00
committed by GitHub
parent e68f50ddff
commit 98a0596c70
16 changed files with 135 additions and 141 deletions

View File

@@ -176,12 +176,12 @@ impl fmt::Debug for Track {
}
impl ListItem for Track {
fn is_playing(&self, queue: Arc<Queue>) -> bool {
fn is_playing(&self, queue: &Queue) -> bool {
let current = queue.get_current();
current.map(|t| t.id() == self.id).unwrap_or(false)
}
fn display_left(&self, library: Arc<Library>) -> String {
fn display_left(&self, library: &Library) -> String {
let formatting = library
.cfg
.values()
@@ -197,7 +197,7 @@ impl ListItem for Track {
}
}
fn display_center(&self, library: Arc<Library>) -> String {
fn display_center(&self, library: &Library) -> String {
let formatting = library
.cfg
.values()
@@ -213,7 +213,7 @@ impl ListItem for Track {
}
}
fn display_right(&self, library: Arc<Library>) -> String {
fn display_right(&self, library: &Library) -> String {
let formatting = library
.cfg
.values()
@@ -238,20 +238,20 @@ impl ListItem for Track {
}
}
fn play(&mut self, queue: Arc<Queue>) {
fn play(&mut self, queue: &Queue) {
let index = queue.append_next(&vec![Playable::Track(self.clone())]);
queue.play(index, true, false);
}
fn play_next(&mut self, queue: Arc<Queue>) {
fn play_next(&mut self, queue: &Queue) {
queue.insert_after_current(Playable::Track(self.clone()));
}
fn queue(&mut self, queue: Arc<Queue>) {
fn queue(&mut self, queue: &Queue) {
queue.append(Playable::Track(self.clone()));
}
fn toggle_saved(&mut self, library: Arc<Library>) {
fn toggle_saved(&mut self, library: &Library) {
if library.is_saved_track(&Playable::Track(self.clone())) {
library.unsave_tracks(vec![self], true);
} else {
@@ -259,11 +259,11 @@ impl ListItem for Track {
}
}
fn save(&mut self, library: Arc<Library>) {
fn save(&mut self, library: &Library) {
library.save_tracks(vec![self], true);
}
fn unsave(&mut self, library: Arc<Library>) {
fn unsave(&mut self, library: &Library) {
library.unsave_tracks(vec![self], true);
}
@@ -309,7 +309,7 @@ impl ListItem for Track {
.map(|id| format!("https://open.spotify.com/track/{id}"))
}
fn album(&self, queue: Arc<Queue>) -> Option<Album> {
fn album(&self, queue: &Queue) -> Option<Album> {
let spotify = queue.get_spotify();
match self.album_id {
@@ -333,7 +333,7 @@ impl ListItem for Track {
}
#[inline]
fn is_saved(&self, library: Arc<Library>) -> Option<bool> {
fn is_saved(&self, library: &Library) -> Option<bool> {
Some(library.is_saved_track(&Playable::Track(self.clone())))
}