mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -3663,7 +3663,6 @@ dependencies = [
|
|||
"fonts_traits",
|
||||
"html5ever",
|
||||
"ipc-channel",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"malloc_size_of",
|
||||
"malloc_size_of_derive",
|
||||
|
@ -3755,7 +3754,6 @@ dependencies = [
|
|||
"histogram",
|
||||
"ipc-channel",
|
||||
"layout_2013",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"malloc_size_of",
|
||||
"metrics",
|
||||
|
@ -3794,7 +3792,6 @@ dependencies = [
|
|||
"fxhash",
|
||||
"ipc-channel",
|
||||
"layout_2020",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"malloc_size_of",
|
||||
"metrics",
|
||||
|
@ -6099,7 +6096,6 @@ dependencies = [
|
|||
"embedder_traits",
|
||||
"euclid",
|
||||
"getopts",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"num_cpus",
|
||||
"serde",
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -108,13 +108,12 @@ impl Build {
|
|||
let num_prefs = self.path_map.len();
|
||||
|
||||
self.output.extend(quote! {
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref #gen_accessors: std::collections::HashMap<String, #accessor_type> = {
|
||||
pub static #gen_accessors: std::sync::LazyLock<std::collections::HashMap<String, #accessor_type>> =
|
||||
std::sync::LazyLock::new(|| {
|
||||
let mut map = std::collections::HashMap::with_capacity(#num_prefs);
|
||||
#(#values)*
|
||||
map
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ fonts = { path = "../fonts" }
|
|||
fonts_traits = { workspace = true }
|
||||
html5ever = { workspace = true }
|
||||
ipc-channel = { workspace = true }
|
||||
lazy_static = { workspace = true }
|
||||
log = { workspace = true }
|
||||
malloc_size_of = { workspace = true }
|
||||
malloc_size_of_derive = { workspace = true }
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
//! as possible.
|
||||
|
||||
use std::collections::{HashMap, LinkedList};
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use script_layout_interface::wrapper_traits::PseudoElementType;
|
||||
use smallvec::SmallVec;
|
||||
use style::computed_values::list_style_type::T as ListStyleType;
|
||||
|
@ -29,8 +29,8 @@ use crate::fragment::{
|
|||
use crate::text::TextRunScanner;
|
||||
use crate::traversal::InorderFlowTraversal;
|
||||
|
||||
lazy_static! {
|
||||
static ref INITIAL_QUOTES: style::ArcSlice<QuotePair> = style::ArcSlice::from_iter_leaked(
|
||||
static INITIAL_QUOTES: LazyLock<style::ArcSlice<QuotePair>> = LazyLock::new(|| {
|
||||
style::ArcSlice::from_iter_leaked(
|
||||
vec![
|
||||
QuotePair {
|
||||
opening: "\u{201c}".to_owned().into(),
|
||||
|
@ -41,9 +41,9 @@ lazy_static! {
|
|||
closing: "\u{2019}".to_owned().into(),
|
||||
},
|
||||
]
|
||||
.into_iter()
|
||||
);
|
||||
}
|
||||
.into_iter(),
|
||||
)
|
||||
});
|
||||
|
||||
// Decimal styles per CSS-COUNTER-STYLES § 6.1:
|
||||
static DECIMAL: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
|
|
|
@ -23,7 +23,6 @@ fonts_traits = { workspace = true }
|
|||
histogram = "0.6.8"
|
||||
ipc-channel = { workspace = true }
|
||||
layout = { path = "../layout", package = "layout_2013" }
|
||||
lazy_static = { workspace = true }
|
||||
log = { workspace = true }
|
||||
malloc_size_of = { workspace = true }
|
||||
metrics = { path = "../metrics" }
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::borrow::ToOwned;
|
|||
use std::cell::{Cell, RefCell};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::process;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, LazyLock, Mutex};
|
||||
|
||||
use app_units::Au;
|
||||
use base::id::{BrowsingContextId, PipelineId};
|
||||
|
@ -48,7 +48,6 @@ use layout::traversal::{
|
|||
};
|
||||
use layout::wrapper::ThreadSafeLayoutNodeHelpers;
|
||||
use layout::{layout_debug, layout_debug_scope, parallel, sequential};
|
||||
use lazy_static::lazy_static;
|
||||
use log::{debug, error, trace, warn};
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
|
||||
|
@ -1557,17 +1556,14 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
|||
})
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref UA_STYLESHEETS: UserAgentStylesheets = {
|
||||
match get_ua_stylesheets() {
|
||||
Ok(stylesheets) => stylesheets,
|
||||
Err(filename) => {
|
||||
error!("Failed to load UA stylesheet {}!", filename);
|
||||
process::exit(1);
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
static UA_STYLESHEETS: LazyLock<UserAgentStylesheets> =
|
||||
LazyLock::new(|| match get_ua_stylesheets() {
|
||||
Ok(stylesheets) => stylesheets,
|
||||
Err(filename) => {
|
||||
error!("Failed to load UA stylesheet {}!", filename);
|
||||
process::exit(1);
|
||||
},
|
||||
});
|
||||
|
||||
struct RegisteredPainterImpl {
|
||||
painter: Box<dyn Painter>,
|
||||
|
|
|
@ -21,7 +21,6 @@ fonts = { path = "../fonts" }
|
|||
fonts_traits = { workspace = true }
|
||||
ipc-channel = { workspace = true }
|
||||
layout = { path = "../layout_2020", package = "layout_2020" }
|
||||
lazy_static = { workspace = true }
|
||||
log = { workspace = true }
|
||||
malloc_size_of = { workspace = true }
|
||||
metrics = { path = "../metrics" }
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::collections::HashMap;
|
|||
use std::fmt::Debug;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
||||
use app_units::Au;
|
||||
use base::id::{BrowsingContextId, PipelineId};
|
||||
|
@ -35,7 +35,6 @@ use layout::query::{
|
|||
};
|
||||
use layout::traversal::RecalcStyle;
|
||||
use layout::{layout_debug, BoxTree, FragmentTree};
|
||||
use lazy_static::lazy_static;
|
||||
use log::{debug, error, warn};
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
|
||||
|
@ -1151,17 +1150,14 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
|||
})
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref UA_STYLESHEETS: UserAgentStylesheets = {
|
||||
match get_ua_stylesheets() {
|
||||
Ok(stylesheets) => stylesheets,
|
||||
Err(filename) => {
|
||||
error!("Failed to load UA stylesheet {}!", filename);
|
||||
process::exit(1);
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
static UA_STYLESHEETS: LazyLock<UserAgentStylesheets> =
|
||||
LazyLock::new(|| match get_ua_stylesheets() {
|
||||
Ok(stylesheets) => stylesheets,
|
||||
Err(filename) => {
|
||||
error!("Failed to load UA stylesheet {}!", filename);
|
||||
process::exit(1);
|
||||
},
|
||||
});
|
||||
|
||||
struct RegisteredPainterImpl {
|
||||
painter: Box<dyn Painter>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue