mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
Define cfg(rtopt) when optimizing. Turn off runtime sanity checks
Naturally, and sadly, turning off sanity checks in the runtime is a noticable performance win. The particular test I'm running goes from ~1.5 s to ~1.3s. Sanity checks are turned *on* when not optimizing, or when cfg includes `rtdebug` or `rtassert`.
This commit is contained in:
parent
4c75d36d0e
commit
30a7a5b8fa
@ -96,7 +96,8 @@ ifdef CFG_DISABLE_OPTIMIZE
|
||||
$(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
|
||||
CFG_RUSTC_FLAGS +=
|
||||
else
|
||||
CFG_RUSTC_FLAGS += -O
|
||||
# The rtopt cfg turns off runtime sanity checks
|
||||
CFG_RUSTC_FLAGS += -O --cfg rtopt
|
||||
endif
|
||||
|
||||
ifdef CFG_ENABLE_DEBUG
|
||||
|
@ -27,8 +27,10 @@ macro_rules! rtdebug (
|
||||
|
||||
macro_rules! rtassert (
|
||||
( $arg:expr ) => ( {
|
||||
if !$arg {
|
||||
rtabort!("assertion failed: %s", stringify!($arg));
|
||||
if ::rt::util::ENFORCE_SANITY {
|
||||
if !$arg {
|
||||
rtabort!("assertion failed: %s", stringify!($arg));
|
||||
}
|
||||
}
|
||||
} )
|
||||
)
|
||||
|
@ -19,6 +19,9 @@ use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
|
||||
#[cfg(target_os="macos")]
|
||||
use unstable::running_on_valgrind;
|
||||
|
||||
// Indicates whether we should perform expensive sanity checks, including rtassert!
|
||||
pub static ENFORCE_SANITY: bool = !cfg!(rtopt) || cfg!(rtdebug) || cfg!(rtassert);
|
||||
|
||||
/// Get the number of cores available
|
||||
pub fn num_cpus() -> uint {
|
||||
#[fixed_stack_segment]; #[inline(never)];
|
||||
|
Loading…
Reference in New Issue
Block a user