nodrop: Add feature flag use_needs_drop; Tag version 0.1.5
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ matrix:
|
|||||||
- rust: nightly
|
- rust: nightly
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
env:
|
env:
|
||||||
- NODROP_FEATURES='no_drop_flag'
|
- NODROP_FEATURES='no_drop_flag use_needs_drop'
|
||||||
script:
|
script:
|
||||||
- |
|
- |
|
||||||
[ -z "$NODROP_FEATURES" ] && cargo build --verbose --features "$FEATURES"
|
[ -z "$NODROP_FEATURES" ] && cargo build --verbose --features "$FEATURES"
|
||||||
|
|||||||
+12
-2
@@ -19,8 +19,8 @@ __ http://bluss.github.io/arrayvec
|
|||||||
.. |crates2| image:: http://meritbadge.herokuapp.com/nodrop
|
.. |crates2| image:: http://meritbadge.herokuapp.com/nodrop
|
||||||
.. _crates2: https://crates.io/crates/nodrop
|
.. _crates2: https://crates.io/crates/nodrop
|
||||||
|
|
||||||
Recent Changes
|
Recent Changes (arrayvec)
|
||||||
--------------
|
-------------------------
|
||||||
|
|
||||||
- 0.3.12
|
- 0.3.12
|
||||||
|
|
||||||
@@ -44,6 +44,16 @@ Recent Changes
|
|||||||
- Added method .into_inner()
|
- Added method .into_inner()
|
||||||
- Added unsafe method .set_len()
|
- Added unsafe method .set_len()
|
||||||
|
|
||||||
|
Recent Changes (nodrop)
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
- 0.1.5
|
||||||
|
|
||||||
|
- Added crate feature ``use_needs_drop`` which is a nightly-only
|
||||||
|
optimization, which skips overwriting if the inner value does not need
|
||||||
|
drop.
|
||||||
|
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "nodrop"
|
name = "nodrop"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
authors = ["bluss"]
|
authors = ["bluss"]
|
||||||
|
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
@@ -17,5 +17,9 @@ keywords = ["container", "drop"]
|
|||||||
# Use no drop flag. See API doc for more info.
|
# Use no drop flag. See API doc for more info.
|
||||||
no_drop_flag = []
|
no_drop_flag = []
|
||||||
|
|
||||||
|
# Optional, nightly channel
|
||||||
|
# Use `needs_drop` to skip overwriting if not necessary
|
||||||
|
use_needs_drop = []
|
||||||
|
|
||||||
[dependencies.odds]
|
[dependencies.odds]
|
||||||
version = "0.2"
|
version = "0.2"
|
||||||
|
|||||||
+25
-4
@@ -1,6 +1,10 @@
|
|||||||
//!
|
//!
|
||||||
//! The **nodrop** crate has the following cargo feature flags:
|
//! The **nodrop** crate has the following cargo feature flags:
|
||||||
//!
|
//!
|
||||||
|
//! - `use_needs_drop`
|
||||||
|
//! - Optional
|
||||||
|
//! - Requires nightly channel.
|
||||||
|
//! - Use `needs_drop` to skip overwriting if not necessary
|
||||||
//! - `no_drop_flag`.
|
//! - `no_drop_flag`.
|
||||||
//! - Optional.
|
//! - Optional.
|
||||||
//! - Requires nightly channel.
|
//! - Requires nightly channel.
|
||||||
@@ -11,6 +15,7 @@
|
|||||||
//!
|
//!
|
||||||
|
|
||||||
#![cfg_attr(feature="no_drop_flag", feature(unsafe_no_drop_flag))]
|
#![cfg_attr(feature="no_drop_flag", feature(unsafe_no_drop_flag))]
|
||||||
|
#![cfg_attr(feature="use_needs_drop", feature(core_intrinsics))]
|
||||||
|
|
||||||
extern crate odds;
|
extern crate odds;
|
||||||
|
|
||||||
@@ -52,12 +57,28 @@ impl<T> NoDrop<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "use_needs_drop"))]
|
||||||
|
#[inline]
|
||||||
|
fn needs_drop<T>() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "use_needs_drop")]
|
||||||
|
#[inline]
|
||||||
|
fn needs_drop<T>() -> bool {
|
||||||
|
unsafe {
|
||||||
|
std::intrinsics::needs_drop::<T>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> Drop for NoDrop<T> {
|
impl<T> Drop for NoDrop<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// no drop flag info: writing repeatedly is idempotent
|
if needs_drop::<T>() {
|
||||||
// inhibit drop
|
// no drop flag info: writing repeatedly is idempotent
|
||||||
unsafe {
|
// inhibit drop
|
||||||
ptr::write(&mut self.0, Flag::Dropped);
|
unsafe {
|
||||||
|
ptr::write(&mut self.0, Flag::Dropped);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user