mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
Replace lazy_static crate with std::sync::LazyLock
in layout and config (#33065)
* replace in layout_thread_2020 Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * replace in layout_thread Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * replace in layout Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * replace in config Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * replace in config_plugins The macro of config_plugins require Send trait bounds Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> --------- Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
This commit is contained in:
parent
c01b733523
commit
016ff5dfa6
12 changed files with 43 additions and 65 deletions
|
@ -14,7 +14,6 @@ path = "lib.rs"
|
|||
embedder_traits = { workspace = true }
|
||||
euclid = { workspace = true }
|
||||
getopts = { workspace = true }
|
||||
lazy_static = { workspace = true }
|
||||
log = { workspace = true }
|
||||
num_cpus = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
|
|
|
@ -10,12 +10,11 @@ use std::fs::{self, File};
|
|||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{RwLock, RwLockReadGuard};
|
||||
use std::sync::{LazyLock, RwLock, RwLockReadGuard};
|
||||
use std::{env, process};
|
||||
|
||||
use euclid::Size2D;
|
||||
use getopts::{Matches, Options};
|
||||
use lazy_static::lazy_static;
|
||||
use log::error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_geometry::DeviceIndependentPixel;
|
||||
|
@ -789,9 +788,7 @@ pub enum ArgumentParsingResult {
|
|||
// Make Opts available globally. This saves having to clone and pass
|
||||
// opts everywhere it is used, which gets particularly cumbersome
|
||||
// when passing through the DOM structures.
|
||||
lazy_static! {
|
||||
static ref OPTIONS: RwLock<Opts> = RwLock::new(default_opts());
|
||||
}
|
||||
static OPTIONS: LazyLock<RwLock<Opts>> = LazyLock::new(|| RwLock::new(default_opts()));
|
||||
|
||||
pub fn set_options(opts: Opts) {
|
||||
MULTIPROCESS.store(opts.multiprocess, Ordering::SeqCst);
|
||||
|
|
|
@ -195,16 +195,16 @@ impl fmt::Display for PrefError {
|
|||
impl std::error::Error for PrefError {}
|
||||
|
||||
pub struct Accessor<P, V> {
|
||||
pub getter: Box<dyn Fn(&P) -> V + Sync>,
|
||||
pub getter: Box<dyn Fn(&P) -> V + Sync + Send>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub setter: Box<dyn Fn(&mut P, V) + Sync>,
|
||||
pub setter: Box<dyn Fn(&mut P, V) + Sync + Send>,
|
||||
}
|
||||
|
||||
impl<P, V> Accessor<P, V> {
|
||||
pub fn new<G, S>(getter: G, setter: S) -> Self
|
||||
where
|
||||
G: Fn(&P) -> V + Sync + 'static,
|
||||
S: Fn(&mut P, V) + Sync + 'static,
|
||||
G: Fn(&P) -> V + Sync + Send + 'static,
|
||||
S: Fn(&mut P, V) + Sync + Send + 'static,
|
||||
{
|
||||
Accessor {
|
||||
getter: Box::new(getter),
|
||||
|
|
|
@ -5,27 +5,25 @@
|
|||
use std::borrow::ToOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use embedder_traits::resources::{self, Resource};
|
||||
use gen::Prefs;
|
||||
use lazy_static::lazy_static;
|
||||
use log::warn;
|
||||
use serde_json::{self, Value};
|
||||
|
||||
use crate::pref_util::Preferences;
|
||||
pub use crate::pref_util::{PrefError, PrefValue};
|
||||
|
||||
lazy_static! {
|
||||
static ref PREFS: Preferences<'static, Prefs> = {
|
||||
let def_prefs: Prefs = serde_json::from_str(&resources::read_string(Resource::Preferences))
|
||||
.expect("Failed to initialize config preferences.");
|
||||
let result = Preferences::new(def_prefs, &gen::PREF_ACCESSORS);
|
||||
for (key, value) in result.iter() {
|
||||
set_stylo_pref_ref(&key, &value);
|
||||
}
|
||||
result
|
||||
};
|
||||
}
|
||||
static PREFS: LazyLock<Preferences<'static, Prefs>> = LazyLock::new(|| {
|
||||
let def_prefs: Prefs = serde_json::from_str(&resources::read_string(Resource::Preferences))
|
||||
.expect("Failed to initialize config preferences.");
|
||||
let result = Preferences::new(def_prefs, &gen::PREF_ACCESSORS);
|
||||
for (key, value) in result.iter() {
|
||||
set_stylo_pref_ref(&key, &value);
|
||||
}
|
||||
result
|
||||
});
|
||||
|
||||
/// A convenience macro for accessing a preference value using its static path.
|
||||
/// Passing an invalid path is a compile-time error.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue