Replace the lazy_static crate with std::sync::LazyLock in components/shared (#33060)

* replace in pub_domains.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace in embedder/resources.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace in base/id.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* replace in net/lib.rs

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* remove lazy_static from components/shared

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

---------

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
This commit is contained in:
Hayashi Mikihiro 2024-08-15 21:05:29 +09:00 committed by GitHub
parent 8f82b2a7cb
commit 86c4e014b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 19 additions and 37 deletions

5
Cargo.lock generated
View file

@ -305,7 +305,6 @@ version = "0.0.1"
dependencies = [ dependencies = [
"base", "base",
"ipc-channel", "ipc-channel",
"lazy_static",
"malloc_size_of", "malloc_size_of",
"malloc_size_of_derive", "malloc_size_of_derive",
"parking_lot", "parking_lot",
@ -335,7 +334,6 @@ version = "0.0.1"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"ipc-channel", "ipc-channel",
"lazy_static",
"malloc_size_of", "malloc_size_of",
"malloc_size_of_derive", "malloc_size_of_derive",
"parking_lot", "parking_lot",
@ -669,7 +667,6 @@ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"euclid", "euclid",
"ipc-channel", "ipc-channel",
"lazy_static",
"malloc_size_of", "malloc_size_of",
"malloc_size_of_derive", "malloc_size_of_derive",
"pixels", "pixels",
@ -1610,7 +1607,6 @@ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"ipc-channel", "ipc-channel",
"keyboard-types", "keyboard-types",
"lazy_static",
"log", "log",
"num-derive", "num-derive",
"num-traits", "num-traits",
@ -4537,7 +4533,6 @@ dependencies = [
"hyper_serde", "hyper_serde",
"image", "image",
"ipc-channel", "ipc-channel",
"lazy_static",
"log", "log",
"malloc_size_of", "malloc_size_of",
"malloc_size_of_derive", "malloc_size_of_derive",

View file

@ -15,7 +15,6 @@ doctest = false
[dependencies] [dependencies]
base = { workspace = true } base = { workspace = true }
ipc-channel = { workspace = true } ipc-channel = { workspace = true }
lazy_static = { workspace = true }
malloc_size_of = { workspace = true } malloc_size_of = { workspace = true }
malloc_size_of_derive = { workspace = true } malloc_size_of_derive = { workspace = true }
parking_lot = { workspace = true } parking_lot = { workspace = true }

View file

@ -15,7 +15,6 @@ doctest = false
[dependencies] [dependencies]
crossbeam-channel = { workspace = true } crossbeam-channel = { workspace = true }
ipc-channel = { workspace = true } ipc-channel = { workspace = true }
lazy_static = { workspace = true }
malloc_size_of = { workspace = true } malloc_size_of = { workspace = true }
malloc_size_of_derive = { workspace = true } malloc_size_of_derive = { workspace = true }
parking_lot = { workspace = true } parking_lot = { workspace = true }

View file

@ -9,10 +9,9 @@
use std::cell::Cell; use std::cell::Cell;
use std::fmt; use std::fmt;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::sync::Arc; use std::sync::{Arc, LazyLock};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use lazy_static::lazy_static;
use malloc_size_of::malloc_size_of_is_0; use malloc_size_of::malloc_size_of_is_0;
use malloc_size_of_derive::MallocSizeOf; use malloc_size_of_derive::MallocSizeOf;
use parking_lot::Mutex; use parking_lot::Mutex;
@ -108,17 +107,15 @@ impl PipelineNamespaceInstaller {
} }
} }
lazy_static! { /// A per-process unique pipeline-namespace-installer.
/// A per-process unique pipeline-namespace-installer. /// Accessible via PipelineNamespace.
/// Accessible via PipelineNamespace. ///
/// /// Use PipelineNamespace::set_installer_sender to initiate with a sender to the constellation,
/// Use PipelineNamespace::set_installer_sender to initiate with a sender to the constellation, /// when a new process has been created.
/// when a new process has been created. ///
/// /// Use PipelineNamespace::fetch_install to install a unique pipeline-namespace from the calling thread.
/// Use PipelineNamespace::fetch_install to install a unique pipeline-namespace from the calling thread. static PIPELINE_NAMESPACE_INSTALLER: LazyLock<Arc<Mutex<PipelineNamespaceInstaller>>> =
static ref PIPELINE_NAMESPACE_INSTALLER: Arc<Mutex<PipelineNamespaceInstaller>> = LazyLock::new(|| Arc::new(Mutex::new(PipelineNamespaceInstaller::default())));
Arc::new(Mutex::new(PipelineNamespaceInstaller::default()));
}
/// Each pipeline ID needs to be unique. However, it also needs to be possible to /// Each pipeline ID needs to be unique. However, it also needs to be possible to
/// generate the pipeline ID from an iframe element (this simplifies a lot of other /// generate the pipeline ID from an iframe element (this simplifies a lot of other

View file

@ -18,7 +18,6 @@ base = { workspace = true }
crossbeam-channel = { workspace = true } crossbeam-channel = { workspace = true }
euclid = { workspace = true } euclid = { workspace = true }
ipc-channel = { workspace = true } ipc-channel = { workspace = true }
lazy_static = { workspace = true }
malloc_size_of = { workspace = true } malloc_size_of = { workspace = true }
malloc_size_of_derive = { workspace = true } malloc_size_of_derive = { workspace = true }
pixels = { path = "../../pixels" } pixels = { path = "../../pixels" }

View file

@ -16,7 +16,6 @@ cfg-if = { workspace = true }
crossbeam-channel = { workspace = true } crossbeam-channel = { workspace = true }
ipc-channel = { workspace = true } ipc-channel = { workspace = true }
keyboard-types = { workspace = true } keyboard-types = { workspace = true }
lazy_static = { workspace = true }
log = { workspace = true } log = { workspace = true }
num-derive = "0.4" num-derive = "0.4"
num-traits = { workspace = true } num-traits = { workspace = true }

View file

@ -3,13 +3,12 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::RwLock; use std::sync::{LazyLock, RwLock};
use cfg_if::cfg_if; use cfg_if::cfg_if;
use lazy_static::lazy_static;
lazy_static! { static RES: LazyLock<RwLock<Option<Box<dyn ResourceReaderMethods + Sync + Send>>>> =
static ref RES: RwLock<Option<Box<dyn ResourceReaderMethods + Sync + Send>>> = { LazyLock::new(|| {
cfg_if! { cfg_if! {
if #[cfg(servo_production)] { if #[cfg(servo_production)] {
RwLock::new(None) RwLock::new(None)
@ -21,8 +20,7 @@ lazy_static! {
RwLock::new(Some(resources_for_tests())) RwLock::new(Some(resources_for_tests()))
} }
} }
}; });
}
pub fn set(reader: Box<dyn ResourceReaderMethods + Sync + Send>) { pub fn set(reader: Box<dyn ResourceReaderMethods + Sync + Send>) {
*RES.write().unwrap() = Some(reader); *RES.write().unwrap() = Some(reader);

View file

@ -23,7 +23,6 @@ hyper = { workspace = true }
hyper_serde = { workspace = true } hyper_serde = { workspace = true }
image = { workspace = true } image = { 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 }

View file

@ -5,6 +5,7 @@
#![deny(unsafe_code)] #![deny(unsafe_code)]
use std::fmt::Display; use std::fmt::Display;
use std::sync::LazyLock;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use base::id::HistoryStateId; use base::id::HistoryStateId;
@ -16,7 +17,6 @@ use hyper_serde::Serde;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER; use ipc_channel::router::ROUTER;
use ipc_channel::Error as IpcError; use ipc_channel::Error as IpcError;
use lazy_static::lazy_static;
use malloc_size_of::malloc_size_of_is_0; use malloc_size_of::malloc_size_of_is_0;
use malloc_size_of_derive::MallocSizeOf; use malloc_size_of_derive::MallocSizeOf;
use mime::Mime; use mime::Mime;
@ -819,6 +819,5 @@ pub fn http_percent_encode(bytes: &[u8]) -> String {
percent_encoding::percent_encode(bytes, HTTP_VALUE).to_string() percent_encoding::percent_encode(bytes, HTTP_VALUE).to_string()
} }
lazy_static! { pub static PRIVILEGED_SECRET: LazyLock<u32> =
pub static ref PRIVILEGED_SECRET: u32 = servo_rand::ServoRng::default().next_u32(); LazyLock::new(|| servo_rand::ServoRng::default().next_u32());
}

View file

@ -16,9 +16,9 @@
use std::collections::HashSet; use std::collections::HashSet;
use std::iter::FromIterator; use std::iter::FromIterator;
use std::sync::LazyLock;
use embedder_traits::resources::{self, Resource}; use embedder_traits::resources::{self, Resource};
use lazy_static::lazy_static;
use servo_url::{Host, ImmutableOrigin, ServoUrl}; use servo_url::{Host, ImmutableOrigin, ServoUrl};
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
@ -28,9 +28,7 @@ pub struct PubDomainRules {
exceptions: HashSet<String>, exceptions: HashSet<String>,
} }
lazy_static! { static PUB_DOMAINS: LazyLock<PubDomainRules> = LazyLock::new(|| load_pub_domains());
static ref PUB_DOMAINS: PubDomainRules = load_pub_domains();
}
impl<'a> FromIterator<&'a str> for PubDomainRules { impl<'a> FromIterator<&'a str> for PubDomainRules {
fn from_iter<T>(iter: T) -> Self fn from_iter<T>(iter: T) -> Self