diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-08-16 23:14:55 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-08-23 21:19:59 -0700 |
| commit | 30a7a5b8fa0f0c6262322d353020ff556708082e (patch) | |
| tree | f35e3f0b3b2f0dd8baad3d447a1c50bc33ba5909 | |
| parent | 4c75d36d0e81508d4e7614104abb44fa19179c03 (diff) | |
| download | rust-30a7a5b8fa0f0c6262322d353020ff556708082e.tar.gz rust-30a7a5b8fa0f0c6262322d353020ff556708082e.zip | |
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`.
| -rw-r--r-- | Makefile.in | 3 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 6 | ||||
| -rw-r--r-- | src/libstd/rt/util.rs | 3 |
3 files changed, 9 insertions, 3 deletions
diff --git a/Makefile.in b/Makefile.in index a9a41a073d0..0575f48c4c4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 600d0bb133e..5378a2c798d 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -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)); + } } } ) ) diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index f2ede8872c2..c3f5b11a930 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -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)]; |
