mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -3663,7 +3663,6 @@ dependencies = [
|
||||||
"fonts_traits",
|
"fonts_traits",
|
||||||
"html5ever",
|
"html5ever",
|
||||||
"ipc-channel",
|
"ipc-channel",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"malloc_size_of",
|
"malloc_size_of",
|
||||||
"malloc_size_of_derive",
|
"malloc_size_of_derive",
|
||||||
|
@ -3755,7 +3754,6 @@ dependencies = [
|
||||||
"histogram",
|
"histogram",
|
||||||
"ipc-channel",
|
"ipc-channel",
|
||||||
"layout_2013",
|
"layout_2013",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"malloc_size_of",
|
"malloc_size_of",
|
||||||
"metrics",
|
"metrics",
|
||||||
|
@ -3794,7 +3792,6 @@ dependencies = [
|
||||||
"fxhash",
|
"fxhash",
|
||||||
"ipc-channel",
|
"ipc-channel",
|
||||||
"layout_2020",
|
"layout_2020",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"malloc_size_of",
|
"malloc_size_of",
|
||||||
"metrics",
|
"metrics",
|
||||||
|
@ -6099,7 +6096,6 @@ dependencies = [
|
||||||
"embedder_traits",
|
"embedder_traits",
|
||||||
"euclid",
|
"euclid",
|
||||||
"getopts",
|
"getopts",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -14,7 +14,6 @@ path = "lib.rs"
|
||||||
embedder_traits = { workspace = true }
|
embedder_traits = { workspace = true }
|
||||||
euclid = { workspace = true }
|
euclid = { workspace = true }
|
||||||
getopts = { workspace = true }
|
getopts = { workspace = true }
|
||||||
lazy_static = { workspace = true }
|
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
num_cpus = { workspace = true }
|
num_cpus = { workspace = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
|
|
|
@ -10,12 +10,11 @@ use std::fs::{self, File};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{RwLock, RwLockReadGuard};
|
use std::sync::{LazyLock, RwLock, RwLockReadGuard};
|
||||||
use std::{env, process};
|
use std::{env, process};
|
||||||
|
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use getopts::{Matches, Options};
|
use getopts::{Matches, Options};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use servo_geometry::DeviceIndependentPixel;
|
use servo_geometry::DeviceIndependentPixel;
|
||||||
|
@ -789,9 +788,7 @@ pub enum ArgumentParsingResult {
|
||||||
// Make Opts available globally. This saves having to clone and pass
|
// Make Opts available globally. This saves having to clone and pass
|
||||||
// opts everywhere it is used, which gets particularly cumbersome
|
// opts everywhere it is used, which gets particularly cumbersome
|
||||||
// when passing through the DOM structures.
|
// when passing through the DOM structures.
|
||||||
lazy_static! {
|
static OPTIONS: LazyLock<RwLock<Opts>> = LazyLock::new(|| RwLock::new(default_opts()));
|
||||||
static ref OPTIONS: RwLock<Opts> = RwLock::new(default_opts());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_options(opts: Opts) {
|
pub fn set_options(opts: Opts) {
|
||||||
MULTIPROCESS.store(opts.multiprocess, Ordering::SeqCst);
|
MULTIPROCESS.store(opts.multiprocess, Ordering::SeqCst);
|
||||||
|
|
|
@ -195,16 +195,16 @@ impl fmt::Display for PrefError {
|
||||||
impl std::error::Error for PrefError {}
|
impl std::error::Error for PrefError {}
|
||||||
|
|
||||||
pub struct Accessor<P, V> {
|
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)]
|
#[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> {
|
impl<P, V> Accessor<P, V> {
|
||||||
pub fn new<G, S>(getter: G, setter: S) -> Self
|
pub fn new<G, S>(getter: G, setter: S) -> Self
|
||||||
where
|
where
|
||||||
G: Fn(&P) -> V + Sync + 'static,
|
G: Fn(&P) -> V + Sync + Send + 'static,
|
||||||
S: Fn(&mut P, V) + Sync + 'static,
|
S: Fn(&mut P, V) + Sync + Send + 'static,
|
||||||
{
|
{
|
||||||
Accessor {
|
Accessor {
|
||||||
getter: Box::new(getter),
|
getter: Box::new(getter),
|
||||||
|
|
|
@ -5,27 +5,25 @@
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use embedder_traits::resources::{self, Resource};
|
use embedder_traits::resources::{self, Resource};
|
||||||
use gen::Prefs;
|
use gen::Prefs;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use serde_json::{self, Value};
|
use serde_json::{self, Value};
|
||||||
|
|
||||||
use crate::pref_util::Preferences;
|
use crate::pref_util::Preferences;
|
||||||
pub use crate::pref_util::{PrefError, PrefValue};
|
pub use crate::pref_util::{PrefError, PrefValue};
|
||||||
|
|
||||||
lazy_static! {
|
static PREFS: LazyLock<Preferences<'static, Prefs>> = LazyLock::new(|| {
|
||||||
static ref PREFS: Preferences<'static, Prefs> = {
|
let def_prefs: Prefs = serde_json::from_str(&resources::read_string(Resource::Preferences))
|
||||||
let def_prefs: Prefs = serde_json::from_str(&resources::read_string(Resource::Preferences))
|
.expect("Failed to initialize config preferences.");
|
||||||
.expect("Failed to initialize config preferences.");
|
let result = Preferences::new(def_prefs, &gen::PREF_ACCESSORS);
|
||||||
let result = Preferences::new(def_prefs, &gen::PREF_ACCESSORS);
|
for (key, value) in result.iter() {
|
||||||
for (key, value) in result.iter() {
|
set_stylo_pref_ref(&key, &value);
|
||||||
set_stylo_pref_ref(&key, &value);
|
}
|
||||||
}
|
result
|
||||||
result
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A convenience macro for accessing a preference value using its static path.
|
/// A convenience macro for accessing a preference value using its static path.
|
||||||
/// Passing an invalid path is a compile-time error.
|
/// Passing an invalid path is a compile-time error.
|
||||||
|
|
|
@ -108,13 +108,12 @@ impl Build {
|
||||||
let num_prefs = self.path_map.len();
|
let num_prefs = self.path_map.len();
|
||||||
|
|
||||||
self.output.extend(quote! {
|
self.output.extend(quote! {
|
||||||
lazy_static::lazy_static! {
|
pub static #gen_accessors: std::sync::LazyLock<std::collections::HashMap<String, #accessor_type>> =
|
||||||
pub static ref #gen_accessors: std::collections::HashMap<String, #accessor_type> = {
|
std::sync::LazyLock::new(|| {
|
||||||
let mut map = std::collections::HashMap::with_capacity(#num_prefs);
|
let mut map = std::collections::HashMap::with_capacity(#num_prefs);
|
||||||
#(#values)*
|
#(#values)*
|
||||||
map
|
map
|
||||||
};
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ fonts = { path = "../fonts" }
|
||||||
fonts_traits = { workspace = true }
|
fonts_traits = { workspace = true }
|
||||||
html5ever = { workspace = true }
|
html5ever = { workspace = true }
|
||||||
ipc-channel = { workspace = true }
|
ipc-channel = { workspace = true }
|
||||||
lazy_static = { workspace = true }
|
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
malloc_size_of = { workspace = true }
|
malloc_size_of = { workspace = true }
|
||||||
malloc_size_of_derive = { workspace = true }
|
malloc_size_of_derive = { workspace = true }
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
//! as possible.
|
//! as possible.
|
||||||
|
|
||||||
use std::collections::{HashMap, LinkedList};
|
use std::collections::{HashMap, LinkedList};
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use script_layout_interface::wrapper_traits::PseudoElementType;
|
use script_layout_interface::wrapper_traits::PseudoElementType;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use style::computed_values::list_style_type::T as ListStyleType;
|
use style::computed_values::list_style_type::T as ListStyleType;
|
||||||
|
@ -29,8 +29,8 @@ use crate::fragment::{
|
||||||
use crate::text::TextRunScanner;
|
use crate::text::TextRunScanner;
|
||||||
use crate::traversal::InorderFlowTraversal;
|
use crate::traversal::InorderFlowTraversal;
|
||||||
|
|
||||||
lazy_static! {
|
static INITIAL_QUOTES: LazyLock<style::ArcSlice<QuotePair>> = LazyLock::new(|| {
|
||||||
static ref INITIAL_QUOTES: style::ArcSlice<QuotePair> = style::ArcSlice::from_iter_leaked(
|
style::ArcSlice::from_iter_leaked(
|
||||||
vec![
|
vec![
|
||||||
QuotePair {
|
QuotePair {
|
||||||
opening: "\u{201c}".to_owned().into(),
|
opening: "\u{201c}".to_owned().into(),
|
||||||
|
@ -41,9 +41,9 @@ lazy_static! {
|
||||||
closing: "\u{2019}".to_owned().into(),
|
closing: "\u{2019}".to_owned().into(),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter(),
|
||||||
);
|
)
|
||||||
}
|
});
|
||||||
|
|
||||||
// Decimal styles per CSS-COUNTER-STYLES § 6.1:
|
// Decimal styles per CSS-COUNTER-STYLES § 6.1:
|
||||||
static DECIMAL: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
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"
|
histogram = "0.6.8"
|
||||||
ipc-channel = { workspace = true }
|
ipc-channel = { workspace = true }
|
||||||
layout = { path = "../layout", package = "layout_2013" }
|
layout = { path = "../layout", package = "layout_2013" }
|
||||||
lazy_static = { workspace = true }
|
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
malloc_size_of = { workspace = true }
|
malloc_size_of = { workspace = true }
|
||||||
metrics = { path = "../metrics" }
|
metrics = { path = "../metrics" }
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::borrow::ToOwned;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, LazyLock, Mutex};
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use base::id::{BrowsingContextId, PipelineId};
|
use base::id::{BrowsingContextId, PipelineId};
|
||||||
|
@ -48,7 +48,6 @@ use layout::traversal::{
|
||||||
};
|
};
|
||||||
use layout::wrapper::ThreadSafeLayoutNodeHelpers;
|
use layout::wrapper::ThreadSafeLayoutNodeHelpers;
|
||||||
use layout::{layout_debug, layout_debug_scope, parallel, sequential};
|
use layout::{layout_debug, layout_debug_scope, parallel, sequential};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use log::{debug, error, trace, warn};
|
use log::{debug, error, trace, warn};
|
||||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||||
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
|
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
|
||||||
|
@ -1557,17 +1556,14 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
static UA_STYLESHEETS: LazyLock<UserAgentStylesheets> =
|
||||||
static ref UA_STYLESHEETS: UserAgentStylesheets = {
|
LazyLock::new(|| match get_ua_stylesheets() {
|
||||||
match get_ua_stylesheets() {
|
Ok(stylesheets) => stylesheets,
|
||||||
Ok(stylesheets) => stylesheets,
|
Err(filename) => {
|
||||||
Err(filename) => {
|
error!("Failed to load UA stylesheet {}!", filename);
|
||||||
error!("Failed to load UA stylesheet {}!", filename);
|
process::exit(1);
|
||||||
process::exit(1);
|
},
|
||||||
},
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RegisteredPainterImpl {
|
struct RegisteredPainterImpl {
|
||||||
painter: Box<dyn Painter>,
|
painter: Box<dyn Painter>,
|
||||||
|
|
|
@ -21,7 +21,6 @@ fonts = { path = "../fonts" }
|
||||||
fonts_traits = { workspace = true }
|
fonts_traits = { workspace = true }
|
||||||
ipc-channel = { workspace = true }
|
ipc-channel = { workspace = true }
|
||||||
layout = { path = "../layout_2020", package = "layout_2020" }
|
layout = { path = "../layout_2020", package = "layout_2020" }
|
||||||
lazy_static = { workspace = true }
|
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
malloc_size_of = { workspace = true }
|
malloc_size_of = { workspace = true }
|
||||||
metrics = { path = "../metrics" }
|
metrics = { path = "../metrics" }
|
||||||
|
|
|
@ -13,7 +13,7 @@ use std::collections::HashMap;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, LazyLock};
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use base::id::{BrowsingContextId, PipelineId};
|
use base::id::{BrowsingContextId, PipelineId};
|
||||||
|
@ -35,7 +35,6 @@ use layout::query::{
|
||||||
};
|
};
|
||||||
use layout::traversal::RecalcStyle;
|
use layout::traversal::RecalcStyle;
|
||||||
use layout::{layout_debug, BoxTree, FragmentTree};
|
use layout::{layout_debug, BoxTree, FragmentTree};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||||
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
|
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
|
||||||
|
@ -1151,17 +1150,14 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
static UA_STYLESHEETS: LazyLock<UserAgentStylesheets> =
|
||||||
static ref UA_STYLESHEETS: UserAgentStylesheets = {
|
LazyLock::new(|| match get_ua_stylesheets() {
|
||||||
match get_ua_stylesheets() {
|
Ok(stylesheets) => stylesheets,
|
||||||
Ok(stylesheets) => stylesheets,
|
Err(filename) => {
|
||||||
Err(filename) => {
|
error!("Failed to load UA stylesheet {}!", filename);
|
||||||
error!("Failed to load UA stylesheet {}!", filename);
|
process::exit(1);
|
||||||
process::exit(1);
|
},
|
||||||
},
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RegisteredPainterImpl {
|
struct RegisteredPainterImpl {
|
||||||
painter: Box<dyn Painter>,
|
painter: Box<dyn Painter>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue