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 --- Cargo.lock | 13 +++++++++++-- crates/ra_assists/Cargo.toml | 2 +- crates/ra_assists/src/ast_editor.rs | 6 ++---- crates/ra_prof/Cargo.toml | 2 +- crates/ra_prof/src/lib.rs | 27 +++++++++++++-------------- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c03d0b75..92a377497 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -873,6 +873,14 @@ name = "numtoa" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "once_cell" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "opaque-debug" version = "0.2.2" @@ -1039,7 +1047,7 @@ dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "ra_db 0.1.0", "ra_fmt 0.1.0", "ra_hir 0.1.0", @@ -1209,7 +1217,7 @@ dependencies = [ name = "ra_prof" version = "0.1.0" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2121,6 +2129,7 @@ dependencies = [ "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" "checksum number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dbf9993e59c894e3c08aa1c2712914e9e6bf1fcbfc6bef283e2183df345a4fee" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +"checksum once_cell 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7a15c6c8c034b56d2f01b23b98cdbbb622f8de99efad0d93d8ea0e608b36a7e" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" "checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index 29d9ceb59..5ddac1e48 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" authors = ["rust-analyzer developers"] [dependencies] -lazy_static = "1.3.0" +once_cell = "0.2.0" join_to_string = "0.1.3" itertools = "0.8.0" arrayvec = "0.4.10" diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index 726e5c0a3..aa7aeaabb 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs @@ -289,12 +289,10 @@ fn ast_node_from_file_text(text: &str) -> TreeArc { } mod tokens { - use lazy_static::lazy_static; + use once_cell::sync::Lazy; use ra_syntax::{AstNode, SourceFile, TreeArc, SyntaxToken, SyntaxKind::*}; - lazy_static! { - static ref SOURCE_FILE: TreeArc = SourceFile::parse(",\n; ;"); - } + static SOURCE_FILE: Lazy> = Lazy::new(|| SourceFile::parse(",\n; ;")); pub(crate) fn comma() -> SyntaxToken<'static> { SOURCE_FILE 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