Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove most #[inline] annotations #119

Merged
merged 4 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ rustc-internal-api = []
rustc-dep-of-std = ["nightly", "core", "compiler_builtins", "alloc", "rustc-internal-api"]
raw = []

# Enables usage of `#[inline]` on far more functions than by default in this
# crate. This may lead to a performance increase but often comes at a compile
# time cost.
inline-more = []

[package.metadata.docs.rs]
features = ["nightly", "rayon", "serde", "raw"]
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let nightly = std::env::var_os("CARGO_FEATURE_NIGHTLY").is_some();
let has_stable_alloc = || autocfg::new().probe_rustc_version(1, 36);

Expand Down
34 changes: 17 additions & 17 deletions src/external_trait_impls/rayon/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct ParIter<'a, K, V, S> {
impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParIter<'a, K, V, S> {
type Item = (&'a K, &'a V);

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand All @@ -39,7 +39,7 @@ impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParIter<'a, K, V, S> {
}

impl<K, V, S> Clone for ParIter<'_, K, V, S> {
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn clone(&self) -> Self {
ParIter { map: self.map }
}
Expand All @@ -65,7 +65,7 @@ pub struct ParKeys<'a, K, V, S> {
impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParKeys<'a, K, V, S> {
type Item = &'a K;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand All @@ -79,7 +79,7 @@ impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParKeys<'a, K, V, S> {
}

impl<K, V, S> Clone for ParKeys<'_, K, V, S> {
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn clone(&self) -> Self {
ParKeys { map: self.map }
}
Expand All @@ -105,7 +105,7 @@ pub struct ParValues<'a, K, V, S> {
impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParValues<'a, K, V, S> {
type Item = &'a V;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand All @@ -119,7 +119,7 @@ impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParValues<'a, K, V, S>
}

impl<K, V, S> Clone for ParValues<'_, K, V, S> {
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn clone(&self) -> Self {
ParValues { map: self.map }
}
Expand Down Expand Up @@ -147,7 +147,7 @@ pub struct ParIterMut<'a, K, V, S> {
impl<'a, K: Send + Sync, V: Send, S: Send> ParallelIterator for ParIterMut<'a, K, V, S> {
type Item = (&'a K, &'a mut V);

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand Down Expand Up @@ -185,7 +185,7 @@ pub struct ParValuesMut<'a, K, V, S> {
impl<'a, K: Send, V: Send, S: Send> ParallelIterator for ParValuesMut<'a, K, V, S> {
type Item = &'a mut V;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand Down Expand Up @@ -220,7 +220,7 @@ pub struct IntoParIter<K, V, S> {
impl<K: Send, V: Send, S: Send> ParallelIterator for IntoParIter<K, V, S> {
type Item = (K, V);

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand Down Expand Up @@ -249,7 +249,7 @@ pub struct ParDrain<'a, K, V, S> {
impl<K: Send, V: Send, S: Send> ParallelIterator for ParDrain<'_, K, V, S> {
type Item = (K, V);

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand All @@ -268,28 +268,28 @@ impl<K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug

impl<K: Sync, V: Sync, S: Sync> HashMap<K, V, S> {
/// Visits (potentially in parallel) immutably borrowed keys in an arbitrary order.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_keys(&self) -> ParKeys<'_, K, V, S> {
ParKeys { map: self }
}

/// Visits (potentially in parallel) immutably borrowed values in an arbitrary order.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_values(&self) -> ParValues<'_, K, V, S> {
ParValues { map: self }
}
}

impl<K: Send, V: Send, S: Send> HashMap<K, V, S> {
/// Visits (potentially in parallel) mutably borrowed values in an arbitrary order.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_values_mut(&mut self) -> ParValuesMut<'_, K, V, S> {
ParValuesMut { map: self }
}

/// Consumes (potentially in parallel) all values in an arbitrary order,
/// while preserving the map's allocated memory for reuse.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_drain(&mut self) -> ParDrain<'_, K, V, S> {
ParDrain { map: self }
}
Expand Down Expand Up @@ -317,7 +317,7 @@ impl<K: Send, V: Send, S: Send> IntoParallelIterator for HashMap<K, V, S> {
type Item = (K, V);
type Iter = IntoParIter<K, V, S>;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn into_par_iter(self) -> Self::Iter {
IntoParIter { map: self }
}
Expand All @@ -327,7 +327,7 @@ impl<'a, K: Sync, V: Sync, S: Sync> IntoParallelIterator for &'a HashMap<K, V, S
type Item = (&'a K, &'a V);
type Iter = ParIter<'a, K, V, S>;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn into_par_iter(self) -> Self::Iter {
ParIter { map: self }
}
Expand All @@ -337,7 +337,7 @@ impl<'a, K: Send + Sync, V: Send, S: Send> IntoParallelIterator for &'a mut Hash
type Item = (&'a K, &'a mut V);
type Iter = ParIterMut<'a, K, V, S>;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn into_par_iter(self) -> Self::Iter {
ParIterMut { map: self }
}
Expand Down
22 changes: 11 additions & 11 deletions src/external_trait_impls/rayon/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct RawParIter<T> {
impl<T> ParallelIterator for RawParIter<T> {
type Item = Bucket<T>;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand All @@ -36,15 +36,15 @@ struct ParIterProducer<T> {
impl<T> UnindexedProducer for ParIterProducer<T> {
type Item = Bucket<T>;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn split(self) -> (Self, Option<Self>) {
let (left, right) = self.iter.split();
let left = ParIterProducer { iter: left };
let right = right.map(|right| ParIterProducer { iter: right });
(left, right)
}

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn fold_with<F>(self, folder: F) -> F
where
F: Folder<Self::Item>,
Expand All @@ -61,7 +61,7 @@ pub struct RawIntoParIter<T> {
impl<T: Send> ParallelIterator for RawIntoParIter<T> {
type Item = T;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand Down Expand Up @@ -92,7 +92,7 @@ unsafe impl<T> Send for RawParDrain<'_, T> {}
impl<T: Send> ParallelIterator for RawParDrain<'_, T> {
type Item = T;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where
C: UnindexedConsumer<Self::Item>,
Expand Down Expand Up @@ -123,7 +123,7 @@ struct ParDrainProducer<T> {
impl<T: Send> UnindexedProducer for ParDrainProducer<T> {
type Item = T;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn split(self) -> (Self, Option<Self>) {
let (left, right) = self.iter.clone().split();
mem::forget(self);
Expand All @@ -132,7 +132,7 @@ impl<T: Send> UnindexedProducer for ParDrainProducer<T> {
(left, right)
}

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn fold_with<F>(mut self, mut folder: F) -> F
where
F: Folder<Self::Item>,
Expand All @@ -153,7 +153,7 @@ impl<T: Send> UnindexedProducer for ParDrainProducer<T> {
}

impl<T> Drop for ParDrainProducer<T> {
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn drop(&mut self) {
// Drop all remaining elements
if mem::needs_drop::<T>() {
Expand All @@ -168,22 +168,22 @@ impl<T> Drop for ParDrainProducer<T> {

impl<T> RawTable<T> {
/// Returns a parallel iterator over the elements in a `RawTable`.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_iter(&self) -> RawParIter<T> {
RawParIter {
iter: unsafe { self.iter().iter },
}
}

/// Returns a parallel iterator over the elements in a `RawTable`.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn into_par_iter(self) -> RawIntoParIter<T> {
RawIntoParIter { table: self }
}

/// Returns a parallel iterator which consumes all elements of a `RawTable`
/// without freeing its memory allocation.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_drain(&mut self) -> RawParDrain<'_, T> {
RawParDrain {
table: NonNull::from(self),
Expand Down
14 changes: 7 additions & 7 deletions src/external_trait_impls/rayon/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ where
{
/// Visits (potentially in parallel) the values representing the difference,
/// i.e. the values that are in `self` but not in `other`.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_difference<'a>(&'a self, other: &'a Self) -> ParDifference<'a, T, S> {
ParDifference { a: self, b: other }
}

/// Visits (potentially in parallel) the values representing the symmetric
/// difference, i.e. the values that are in `self` or in `other` but not in both.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_symmetric_difference<'a>(
&'a self,
other: &'a Self,
Expand All @@ -231,14 +231,14 @@ where

/// Visits (potentially in parallel) the values representing the
/// intersection, i.e. the values that are both in `self` and `other`.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_intersection<'a>(&'a self, other: &'a Self) -> ParIntersection<'a, T, S> {
ParIntersection { a: self, b: other }
}

/// Visits (potentially in parallel) the values representing the union,
/// i.e. all the values in `self` or `other`, without duplicates.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_union<'a>(&'a self, other: &'a Self) -> ParUnion<'a, T, S> {
ParUnion { a: self, b: other }
}
Expand Down Expand Up @@ -287,7 +287,7 @@ where
{
/// Consumes (potentially in parallel) all values in an arbitrary order,
/// while preserving the set's allocated memory for reuse.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub fn par_drain(&mut self) -> ParDrain<'_, T, S> {
ParDrain { set: self }
}
Expand All @@ -297,7 +297,7 @@ impl<T: Send, S: Send> IntoParallelIterator for HashSet<T, S> {
type Item = T;
type Iter = IntoParIter<T, S>;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn into_par_iter(self) -> Self::Iter {
IntoParIter { set: self }
}
Expand All @@ -307,7 +307,7 @@ impl<'a, T: Sync, S: Sync> IntoParallelIterator for &'a HashSet<T, S> {
type Item = &'a T;
type Iter = ParIter<'a, T, S>;

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn into_par_iter(self) -> Self::Iter {
ParIter { set: self }
}
Expand Down
12 changes: 6 additions & 6 deletions src/external_trait_impls/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod size_hint {
/// This presumably exists to prevent denial of service attacks.
///
/// Original discussion: https://github.com/serde-rs/serde/issues/1114.
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
pub(super) fn cautious(hint: Option<usize>) -> usize {
cmp::min(hint.unwrap_or(0), 4096)
}
Expand All @@ -27,7 +27,7 @@ mod map {
V: Serialize,
H: BuildHasher,
{
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand Down Expand Up @@ -62,7 +62,7 @@ mod map {
formatter.write_str("a map")
}

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'de>,
Expand Down Expand Up @@ -104,7 +104,7 @@ mod set {
T: Serialize + Eq + Hash,
H: BuildHasher,
{
#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand Down Expand Up @@ -137,7 +137,7 @@ mod set {
formatter.write_str("a sequence")
}

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
Expand Down Expand Up @@ -178,7 +178,7 @@ mod set {
formatter.write_str("a sequence")
}

#[inline]
#[cfg_attr(feature = "inline-more", inline)]
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
Expand Down
Loading