*: Remove lazy_static in favor of once_cell (#3110)

This commit is contained in:
Hannes 2022-11-14 05:24:52 +01:00 committed by GitHub
parent 8b378d56d3
commit 7daa0c1145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 19 deletions

View File

@ -86,7 +86,6 @@ futures = "0.3.1"
futures-timer = "3.0.2" # Explicit dependency to be used in `wasm-bindgen` feature
getrandom = "0.2.3" # Explicit dependency to be used in `wasm-bindgen` feature
instant = "0.1.11" # Explicit dependency to be used in `wasm-bindgen` feature
lazy_static = "1.2"
libp2p-autonat = { version = "0.9.0", path = "protocols/autonat", optional = true }
libp2p-core = { version = "0.38.0", path = "core" }

View File

@ -19,7 +19,6 @@ fnv = "1.0"
futures = { version = "0.3.1", features = ["executor", "thread-pool"] }
futures-timer = "3"
instant = "0.1.11"
lazy_static = "1.2"
libsecp256k1 = { version = "0.7.0", optional = true }
log = "0.4"
multiaddr = { version = "0.16.0" }
@ -29,6 +28,7 @@ p256 = { version = "0.11.1", default-features = false, features = ["ecdsa"], opt
parking_lot = "0.12.0"
pin-project = "1.0.0"
prost = "0.11"
once_cell = "1.16.0"
rand = "0.8"
rw-stream-sink = { version = "0.3.0", path = "../misc/rw-stream-sink" }
sha2 = "0.10.0"

View File

@ -27,8 +27,8 @@ use futures::{
task::Context,
task::Poll,
};
use lazy_static::lazy_static;
use multiaddr::{Multiaddr, Protocol};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use rw_stream_sink::RwStreamSink;
use std::{
@ -38,9 +38,7 @@ use std::{
pin::Pin,
};
lazy_static! {
static ref HUB: Hub = Hub(Mutex::new(FnvHashMap::default()));
}
static HUB: Lazy<Hub> = Lazy::new(|| Hub(Mutex::new(FnvHashMap::default())));
struct Hub(Mutex<FnvHashMap<NonZeroU64, ChannelSender>>);

View File

@ -12,9 +12,9 @@ repository = "https://github.com/libp2p/rust-libp2p"
bytes = "1"
curve25519-dalek = "3.0.0"
futures = "0.3.1"
lazy_static = "1.2"
libp2p-core = { version = "0.38.0", path = "../../core" }
log = "0.4"
once_cell = "1.16.0"
prost = "0.11"
rand = "0.8.3"
sha2 = "0.10.0"

View File

@ -309,6 +309,7 @@ impl snow::types::Random for Rng {}
mod tests {
use super::*;
use crate::X25519;
use once_cell::sync::Lazy;
#[test]
fn handshake_hashes_disagree_if_prologue_differs() {
@ -337,7 +338,5 @@ mod tests {
}
// Hack to work around borrow-checker.
lazy_static::lazy_static! {
static ref TEST_KEY: Keypair<X25519> = Keypair::<X25519>::new();
}
static TEST_KEY: Lazy<Keypair<X25519>> = Lazy::new(Keypair::<X25519>::new);
}

View File

@ -25,9 +25,9 @@
use crate::{NoiseConfig, NoiseError, Protocol, ProtocolParams};
use curve25519_dalek::edwards::CompressedEdwardsY;
use lazy_static::lazy_static;
use libp2p_core::UpgradeInfo;
use libp2p_core::{identity, identity::ed25519};
use once_cell::sync::Lazy;
use rand::Rng;
use sha2::{Digest, Sha512};
use x25519_dalek::{x25519, X25519_BASEPOINT_BYTES};
@ -35,20 +35,24 @@ use zeroize::Zeroize;
use super::*;
lazy_static! {
static ref PARAMS_IK: ProtocolParams = "Noise_IK_25519_ChaChaPoly_SHA256"
static PARAMS_IK: Lazy<ProtocolParams> = Lazy::new(|| {
"Noise_IK_25519_ChaChaPoly_SHA256"
.parse()
.map(ProtocolParams)
.expect("Invalid protocol name");
static ref PARAMS_IX: ProtocolParams = "Noise_IX_25519_ChaChaPoly_SHA256"
.expect("Invalid protocol name")
});
static PARAMS_IX: Lazy<ProtocolParams> = Lazy::new(|| {
"Noise_IX_25519_ChaChaPoly_SHA256"
.parse()
.map(ProtocolParams)
.expect("Invalid protocol name");
static ref PARAMS_XX: ProtocolParams = "Noise_XX_25519_ChaChaPoly_SHA256"
.expect("Invalid protocol name")
});
static PARAMS_XX: Lazy<ProtocolParams> = Lazy::new(|| {
"Noise_XX_25519_ChaChaPoly_SHA256"
.parse()
.map(ProtocolParams)
.expect("Invalid protocol name");
}
.expect("Invalid protocol name")
});
/// A X25519 key.
#[derive(Clone)]