Remove an unneeded arc reference count bump on each pref access.

This commit is contained in:
Emilio Cobos Álvarez 2023-06-08 11:07:19 +02:00
parent ac09fdf0c7
commit cb76dbabf4
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A

View file

@ -6,7 +6,7 @@ use serde_json::Value;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, RwLock}; use std::sync::RwLock;
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum PrefValue { pub enum PrefValue {
@ -184,7 +184,7 @@ impl<P, V> Accessor<P, V> {
} }
pub struct Preferences<'m, P> { pub struct Preferences<'m, P> {
user_prefs: Arc<RwLock<P>>, user_prefs: RwLock<P>,
default_prefs: P, default_prefs: P,
accessors: &'m HashMap<String, Accessor<P, PrefValue>>, accessors: &'m HashMap<String, Accessor<P, PrefValue>>,
} }
@ -194,15 +194,15 @@ impl<'m, P: Clone> Preferences<'m, P> {
/// can always be restored using `reset` or `reset_all`. /// can always be restored using `reset` or `reset_all`.
pub fn new(default_prefs: P, accessors: &'m HashMap<String, Accessor<P, PrefValue>>) -> Self { pub fn new(default_prefs: P, accessors: &'m HashMap<String, Accessor<P, PrefValue>>) -> Self {
Self { Self {
user_prefs: Arc::new(RwLock::new(default_prefs.clone())), user_prefs: RwLock::new(default_prefs.clone()),
default_prefs, default_prefs,
accessors, accessors,
} }
} }
/// Access to the data structure holding the preference values. /// Access to the data structure holding the preference values.
pub fn values(&self) -> Arc<RwLock<P>> { pub fn values(&self) -> &RwLock<P> {
Arc::clone(&self.user_prefs) &self.user_prefs
} }
/// Retrieve a preference using its key /// Retrieve a preference using its key