From 1667b5cf52a8f2854c7299242820c951eab50f7a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 7 May 2019 20:54:33 +0300 Subject: switch to once_cell from lazy_static --- crates/ra_prof/Cargo.toml | 2 +- crates/ra_prof/src/lib.rs | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'crates/ra_prof') diff --git a/crates/ra_prof/Cargo.toml b/crates/ra_prof/Cargo.toml index 19ce21783..5f23e865c 100644 --- a/crates/ra_prof/Cargo.toml +++ b/crates/ra_prof/Cargo.toml @@ -6,4 +6,4 @@ authors = ["rust-analyzer developers"] publish = false [dependencies] -lazy_static = "1.3.0" \ No newline at end of file +once_cell = "0.2.0" diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index 9ecb8e744..e56446c9f 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs @@ -1,13 +1,14 @@ -use std::cell::RefCell; -use std::time::{Duration, Instant}; -use std::mem; -use std::io::{stderr, Write}; -use std::iter::repeat; -use std::collections::{HashSet}; -use std::default::Default; -use std::iter::FromIterator; -use std::sync::{RwLock, atomic::{AtomicBool, Ordering}}; -use lazy_static::lazy_static; +use std::{ + cell::RefCell, + time::{Duration, Instant}, + mem, + io::{stderr, Write}, + iter::repeat, + collections::HashSet, + sync::{RwLock, atomic::{AtomicBool, Ordering}}, +}; + +use once_cell::sync::Lazy; /// Set profiling filter. It specifies descriptions allowed to profile. /// This is helpful when call stack has too many nested profiling scopes. @@ -21,7 +22,7 @@ use lazy_static::lazy_static; /// ``` pub fn set_filter(f: Filter) { PROFILING_ENABLED.store(f.depth > 0, Ordering::SeqCst); - let set = HashSet::from_iter(f.allowed.iter().cloned()); + let set: HashSet<_> = f.allowed.iter().cloned().collect(); let mut old = FILTER.write().unwrap(); let filter_data = FilterData { depth: f.depth, @@ -161,9 +162,7 @@ struct FilterData { static PROFILING_ENABLED: AtomicBool = AtomicBool::new(false); -lazy_static! { - static ref FILTER: RwLock = RwLock::new(Default::default()); -} +static FILTER: Lazy> = Lazy::new(Default::default); thread_local!(static PROFILE_STACK: RefCell = RefCell::new(ProfileStack::new())); -- cgit v1.2.3