aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHayashi Mikihiro <34ttrweoewiwe28@gmail.com>2024-08-16 01:28:04 +0900
committerGitHub <noreply@github.com>2024-08-15 16:28:04 +0000
commit016ff5dfa67d05b5c5d1d3fc42bf9f4fbeb537c1 (patch)
tree7e960ab68898b88ef06808872d70a17e2eaeb8c8
parentc01b733523085bb9365601c252b7b49154383631 (diff)
downloadservo-016ff5dfa67d05b5c5d1d3fc42bf9f4fbeb537c1.tar.gz
servo-016ff5dfa67d05b5c5d1d3fc42bf9f4fbeb537c1.zip
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>
-rw-r--r--Cargo.lock4
-rw-r--r--components/config/Cargo.toml1
-rw-r--r--components/config/opts.rs7
-rw-r--r--components/config/pref_util.rs8
-rw-r--r--components/config/prefs.rs22
-rw-r--r--components/config_plugins/lib.rs7
-rw-r--r--components/layout/Cargo.toml1
-rw-r--r--components/layout/generated_content.rs12
-rw-r--r--components/layout_thread/Cargo.toml1
-rw-r--r--components/layout_thread/lib.rs22
-rw-r--r--components/layout_thread_2020/Cargo.toml1
-rw-r--r--components/layout_thread_2020/lib.rs22
12 files changed, 43 insertions, 65 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f8245101a08..22a64ef8fc7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
diff --git a/components/config/Cargo.toml b/components/config/Cargo.toml
index 223e1e08fba..b2658507d40 100644
--- a/components/config/Cargo.toml
+++ b/components/config/Cargo.toml
@@ -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"] }
diff --git a/components/config/opts.rs b/components/config/opts.rs
index 0f909148859..9e146c1375b 100644
--- a/components/config/opts.rs
+++ b/components/config/opts.rs
@@ -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);
diff --git a/components/config/pref_util.rs b/components/config/pref_util.rs
index f79b0d7e22e..4499cd89d37 100644
--- a/components/config/pref_util.rs
+++ b/components/config/pref_util.rs
@@ -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),
diff --git a/components/config/prefs.rs b/components/config/prefs.rs
index d10ec42ce33..65d7b987253 100644
--- a/components/config/prefs.rs
+++ b/components/config/prefs.rs
@@ -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.
diff --git a/components/config_plugins/lib.rs b/components/config_plugins/lib.rs
index 7e7badc3d2d..d419310dd84 100644
--- a/components/config_plugins/lib.rs
+++ b/components/config_plugins/lib.rs
@@ -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
- };
- }
+ });
});
}
diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml
index 1c716acf9db..164cf68026a 100644
--- a/components/layout/Cargo.toml
+++ b/components/layout/Cargo.toml
@@ -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 }
diff --git a/components/layout/generated_content.rs b/components/layout/generated_content.rs
index 3a50024d522..9cadcbc8aa6 100644
--- a/components/layout/generated_content.rs
+++ b/components/layout/generated_content.rs
@@ -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'];
diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml
index 53331fedd80..517cae255fd 100644
--- a/components/layout_thread/Cargo.toml
+++ b/components/layout_thread/Cargo.toml
@@ -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" }
diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs
index d4e34e7b182..77f118d3421 100644
--- a/components/layout_thread/lib.rs
+++ b/components/layout_thread/lib.rs
@@ -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>,
diff --git a/components/layout_thread_2020/Cargo.toml b/components/layout_thread_2020/Cargo.toml
index 8024c74e88d..3e6e80cce1c 100644
--- a/components/layout_thread_2020/Cargo.toml
+++ b/components/layout_thread_2020/Cargo.toml
@@ -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" }
diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs
index 84ff7d2fbed..4038fa92952 100644
--- a/components/layout_thread_2020/lib.rs
+++ b/components/layout_thread_2020/lib.rs
@@ -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>,