diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-02-27 19:53:03 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-02-28 10:46:12 -0800 |
| commit | d5aa795aa5f316bc5f43508df5bc41cba0a61ea8 (patch) | |
| tree | 7f249584ed7618932165c489a885c22f5a7b6a7f /src/libstd | |
| parent | f01a9a8d02f6c09b89a3cecadaa5b62073381180 (diff) | |
| download | rust-d5aa795aa5f316bc5f43508df5bc41cba0a61ea8.tar.gz rust-d5aa795aa5f316bc5f43508df5bc41cba0a61ea8.zip | |
std: Add cfg(test) to UnsafeArc assertions
This is a ubiquitous type in concurrent code, and the assertions are causing significant code bloat for simple operations such as reading the pointer (injecting a failure point, etc). I am testing executable sizes with no I/O implementations (everything stubbed out to return nothing), and this took the size of a libnative executable from 328K to 207K (37% reduction in size), so I think that this is one assertion that's well worth configuring off for now.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sync/arc.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs index 5c452018b9b..10369a52f0f 100644 --- a/src/libstd/sync/arc.rs +++ b/src/libstd/sync/arc.rs @@ -80,7 +80,8 @@ impl<T: Send> UnsafeArc<T> { #[inline] pub fn get(&self) -> *mut T { unsafe { - assert!((*self.data).count.load(Relaxed) > 0); + // FIXME(#12049): this needs some sort of debug assertion + if cfg!(test) { assert!((*self.data).count.load(Relaxed) > 0); } return &mut (*self.data).data as *mut T; } } @@ -90,7 +91,8 @@ impl<T: Send> UnsafeArc<T> { #[inline] pub fn get_immut(&self) -> *T { unsafe { - assert!((*self.data).count.load(Relaxed) > 0); + // FIXME(#12049): this needs some sort of debug assertion + if cfg!(test) { assert!((*self.data).count.load(Relaxed) > 0); } return &(*self.data).data as *T; } } @@ -109,7 +111,8 @@ impl<T: Send> Clone for UnsafeArc<T> { unsafe { // This barrier might be unnecessary, but I'm not sure... let old_count = (*self.data).count.fetch_add(1, Acquire); - assert!(old_count >= 1); + // FIXME(#12049): this needs some sort of debug assertion + if cfg!(test) { assert!(old_count >= 1); } return UnsafeArc { data: self.data }; } } @@ -127,7 +130,8 @@ impl<T> Drop for UnsafeArc<T>{ // Must be acquire+release, not just release, to make sure this // doesn't get reordered to after the unwrapper pointer load. let old_count = (*self.data).count.fetch_sub(1, SeqCst); - assert!(old_count >= 1); + // FIXME(#12049): this needs some sort of debug assertion + if cfg!(test) { assert!(old_count >= 1); } if old_count == 1 { let _: ~ArcData<T> = cast::transmute(self.data); } |
