Skip to content

Commit 8a8f5d9

Browse files
committed
removed lazy-static and formatted with cargo fmt
1 parent 2ef05fe commit 8a8f5d9

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ addr2line = { version = "0.9.0", optional = true, default-features = false, feat
3434
findshlibs = { version = "0.5.0", optional = true }
3535
memmap = { version = "0.7.0", optional = true }
3636
goblin = { version = "0.0.23", optional = true, default-features = false, features = ['std'] }
37-
lazy_static = { version = "1.3", optional = true }
3837

3938
[target.'cfg(windows)'.dependencies]
4039
winapi = { version = "0.3.3", optional = true }
@@ -99,7 +98,7 @@ kernel32 = []
9998
libbacktrace = ["backtrace-sys"]
10099
dladdr = []
101100
coresymbolication = []
102-
gimli-symbolize = ["addr2line", "findshlibs", "memmap", "goblin", "lazy_static"]
101+
gimli-symbolize = ["addr2line", "findshlibs", "memmap", "goblin"]
103102

104103
#=======================================
105104
# Methods of serialization

src/symbolize/gimli.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use core::convert::TryFrom;
1515
use core::mem;
1616
use core::u32;
1717
use findshlibs::{self, Segment, SharedLibrary};
18-
use lazy_static::lazy_static;
1918
use libc::c_void;
2019
use memmap::Mmap;
2120
use std::env;
@@ -330,23 +329,26 @@ impl Mapping {
330329
}
331330
}
332331

333-
lazy_static! {
334-
// A very small, very simple LRU cache for debug info mappings.
335-
//
336-
// The hit rate should be very high, since the typical stack doesn't cross
337-
// between many shared libraries.
338-
//
339-
// The `addr2line::Context` structures are pretty expensive to create. Its
340-
// cost is expected to be amortized by subsequent `locate` queries, which
341-
// leverage the structures built when constructing `addr2line::Context`s to
342-
// get nice speedups. If we didn't have this cache, that amortization would
343-
// never happen, and symbolicating backtraces would be ssssllllooooowwww.
344-
static ref MAPPINGS_CACHE: Mutex<Vec<(PathBuf, Mapping)>>
345-
= Mutex::new(Vec::with_capacity(MAPPINGS_CACHE_SIZE));
332+
// A very small, very simple LRU cache for debug info mappings.
333+
//
334+
// The hit rate should be very high, since the typical stack doesn't cross
335+
// between many shared libraries.
336+
//
337+
// The `addr2line::Context` structures are pretty expensive to create. Its
338+
// cost is expected to be amortized by subsequent `locate` queries, which
339+
// leverage the structures built when constructing `addr2line::Context`s to
340+
// get nice speedups. If we didn't have this cache, that amortization would
341+
// never happen, and symbolicating backtraces would be ssssllllooooowwww.
342+
static mut MAPPINGS_CACHE: Option<Mutex<Vec<(PathBuf, Mapping)>>> = None;
343+
344+
fn lazy_cache() -> &'static Mutex<Vec<(PathBuf, Mapping)>> {
345+
unsafe {
346+
MAPPINGS_CACHE.get_or_insert_with(|| Mutex::new(Vec::with_capacity(MAPPINGS_CACHE_SIZE)))
347+
}
346348
}
347349

348350
pub fn clear_symbol_cache() {
349-
if let Ok(mut cache) = MAPPINGS_CACHE.lock() {
351+
if let Ok(mut cache) = lazy_cache().lock() {
350352
cache.clear();
351353
}
352354
}
@@ -355,8 +357,7 @@ fn with_mapping_for_path<F>(path: PathBuf, f: F)
355357
where
356358
F: FnMut(&Context<'_>),
357359
{
358-
if let Ok(mut cache) = MAPPINGS_CACHE.lock() {
359-
360+
if let Ok(mut cache) = lazy_cache().lock() {
360361
let idx = cache.iter().position(|&(ref p, _)| p == &path);
361362

362363
// Invariant: after this conditional completes without early returning

src/symbolize/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ cfg_if::cfg_if! {
482482
mod libbacktrace;
483483
use self::libbacktrace::resolve as resolve_imp;
484484
use self::libbacktrace::Symbol as SymbolImp;
485-
485+
486486
fn noop_clear_symbol_cache() {}
487487
use noop_clear_symbol_cache as clear_imp;
488488
} else if #[cfg(all(unix,
@@ -491,14 +491,14 @@ cfg_if::cfg_if! {
491491
mod dladdr_resolve;
492492
use self::dladdr_resolve::resolve as resolve_imp;
493493
use self::dladdr_resolve::Symbol as SymbolImp;
494-
494+
495495
fn noop_clear_symbol_cache() {}
496496
use noop_clear_symbol_cache as clear_imp;
497497
} else {
498498
mod noop;
499499
use self::noop::resolve as resolve_imp;
500500
use self::noop::Symbol as SymbolImp;
501-
501+
502502
fn noop_clear_symbol_cache() {}
503503
use noop_clear_symbol_cache as clear_imp;
504504
}

0 commit comments

Comments
 (0)