Skip to content

Commit fada07b

Browse files
committed
Simplify log! when disabled by not(debug_assertions)
Simpler code means less for LLVM to prune -> faster compilation. Also, use `eprintln!` for stderr when enabled, rather than stdout.
1 parent 8155de7 commit fada07b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

rayon-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use std::str::FromStr;
3434

3535
extern crate crossbeam_deque;
3636
extern crate crossbeam_queue;
37+
#[cfg(any(debug_assertions, rayon_unstable))]
3738
#[macro_use]
3839
extern crate lazy_static;
3940
extern crate num_cpus;

rayon-core/src/log.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
//! replacement of the now deprecated `RAYON_RS_LOG` environment
99
//! variable, which is still supported for backwards compatibility.
1010
11+
#[cfg(debug_assertions)]
1112
use std::env;
1213

13-
#[derive(Debug)]
14+
#[cfg_attr(debug_assertions, derive(Debug))]
15+
#[cfg_attr(not(debug_assertions), allow(dead_code))]
1416
pub(super) enum Event {
1517
Tickle {
1618
worker: usize,
@@ -87,19 +89,28 @@ pub(super) enum Event {
8789
},
8890
}
8991

90-
pub(super) const DUMP_LOGS: bool = cfg!(debug_assertions);
91-
92+
#[cfg(debug_assertions)]
9293
lazy_static! {
9394
pub(super) static ref LOG_ENV: bool =
9495
env::var("RAYON_LOG").is_ok() || env::var("RAYON_RS_LOG").is_ok();
9596
}
9697

98+
#[cfg(debug_assertions)]
99+
macro_rules! log {
100+
($event:expr) => {
101+
if *$crate::log::LOG_ENV {
102+
eprintln!("{:?}", $event);
103+
}
104+
};
105+
}
106+
107+
#[cfg(not(debug_assertions))]
97108
macro_rules! log {
98109
($event:expr) => {
99-
if ::log::DUMP_LOGS {
100-
if *::log::LOG_ENV {
101-
println!("{:?}", $event);
102-
}
110+
if false {
111+
// Expand `$event` so it still appears used, but without
112+
// any of the formatting code to be optimized away.
113+
$event;
103114
}
104115
};
105116
}

0 commit comments

Comments
 (0)