Skip to content

Commit 4e9e27d

Browse files
committed
Add back many #[inline] behind a #[cfg]
1 parent 6d20b6b commit 4e9e27d

File tree

11 files changed

+304
-5
lines changed

11 files changed

+304
-5
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ rustc-internal-api = []
4343
rustc-dep-of-std = ["nightly", "core", "compiler_builtins", "alloc", "rustc-internal-api"]
4444
raw = []
4545

46+
# Enables usage of `#[inline]` on far more functions than by default in this
47+
# crate. This may lead to a performance increase but often comes at a compile
48+
# time cost.
49+
inline-more = []
50+
4651
[package.metadata.docs.rs]
4752
features = ["nightly", "rayon", "serde", "raw"]

src/external_trait_impls/rayon/map.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct ParIter<'a, K, V, S> {
2222
impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParIter<'a, K, V, S> {
2323
type Item = (&'a K, &'a V);
2424

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

4041
impl<K, V, S> Clone for ParIter<'_, K, V, S> {
42+
#[cfg_attr(feature = "inline-more", inline)]
4143
fn clone(&self) -> Self {
4244
ParIter { map: self.map }
4345
}
@@ -63,6 +65,7 @@ pub struct ParKeys<'a, K, V, S> {
6365
impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParKeys<'a, K, V, S> {
6466
type Item = &'a K;
6567

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

7881
impl<K, V, S> Clone for ParKeys<'_, K, V, S> {
82+
#[cfg_attr(feature = "inline-more", inline)]
7983
fn clone(&self) -> Self {
8084
ParKeys { map: self.map }
8185
}
@@ -101,6 +105,7 @@ pub struct ParValues<'a, K, V, S> {
101105
impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParValues<'a, K, V, S> {
102106
type Item = &'a V;
103107

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

116121
impl<K, V, S> Clone for ParValues<'_, K, V, S> {
122+
#[cfg_attr(feature = "inline-more", inline)]
117123
fn clone(&self) -> Self {
118124
ParValues { map: self.map }
119125
}
@@ -141,6 +147,7 @@ pub struct ParIterMut<'a, K, V, S> {
141147
impl<'a, K: Send + Sync, V: Send, S: Send> ParallelIterator for ParIterMut<'a, K, V, S> {
142148
type Item = (&'a K, &'a mut V);
143149

150+
#[cfg_attr(feature = "inline-more", inline)]
144151
fn drive_unindexed<C>(self, consumer: C) -> C::Result
145152
where
146153
C: UnindexedConsumer<Self::Item>,
@@ -178,6 +185,7 @@ pub struct ParValuesMut<'a, K, V, S> {
178185
impl<'a, K: Send, V: Send, S: Send> ParallelIterator for ParValuesMut<'a, K, V, S> {
179186
type Item = &'a mut V;
180187

188+
#[cfg_attr(feature = "inline-more", inline)]
181189
fn drive_unindexed<C>(self, consumer: C) -> C::Result
182190
where
183191
C: UnindexedConsumer<Self::Item>,
@@ -212,6 +220,7 @@ pub struct IntoParIter<K, V, S> {
212220
impl<K: Send, V: Send, S: Send> ParallelIterator for IntoParIter<K, V, S> {
213221
type Item = (K, V);
214222

223+
#[cfg_attr(feature = "inline-more", inline)]
215224
fn drive_unindexed<C>(self, consumer: C) -> C::Result
216225
where
217226
C: UnindexedConsumer<Self::Item>,
@@ -240,6 +249,7 @@ pub struct ParDrain<'a, K, V, S> {
240249
impl<K: Send, V: Send, S: Send> ParallelIterator for ParDrain<'_, K, V, S> {
241250
type Item = (K, V);
242251

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

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

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

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

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

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

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

340+
#[cfg_attr(feature = "inline-more", inline)]
324341
fn into_par_iter(self) -> Self::Iter {
325342
ParIterMut { map: self }
326343
}

src/external_trait_impls/rayon/raw.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct RawParIter<T> {
1818
impl<T> ParallelIterator for RawParIter<T> {
1919
type Item = Bucket<T>;
2020

21+
#[cfg_attr(feature = "inline-more", inline)]
2122
fn drive_unindexed<C>(self, consumer: C) -> C::Result
2223
where
2324
C: UnindexedConsumer<Self::Item>,
@@ -35,13 +36,15 @@ struct ParIterProducer<T> {
3536
impl<T> UnindexedProducer for ParIterProducer<T> {
3637
type Item = Bucket<T>;
3738

39+
#[cfg_attr(feature = "inline-more", inline)]
3840
fn split(self) -> (Self, Option<Self>) {
3941
let (left, right) = self.iter.split();
4042
let left = ParIterProducer { iter: left };
4143
let right = right.map(|right| ParIterProducer { iter: right });
4244
(left, right)
4345
}
4446

47+
#[cfg_attr(feature = "inline-more", inline)]
4548
fn fold_with<F>(self, folder: F) -> F
4649
where
4750
F: Folder<Self::Item>,
@@ -58,6 +61,7 @@ pub struct RawIntoParIter<T> {
5861
impl<T: Send> ParallelIterator for RawIntoParIter<T> {
5962
type Item = T;
6063

64+
#[cfg_attr(feature = "inline-more", inline)]
6165
fn drive_unindexed<C>(self, consumer: C) -> C::Result
6266
where
6367
C: UnindexedConsumer<Self::Item>,
@@ -88,6 +92,7 @@ unsafe impl<T> Send for RawParDrain<'_, T> {}
8892
impl<T: Send> ParallelIterator for RawParDrain<'_, T> {
8993
type Item = T;
9094

95+
#[cfg_attr(feature = "inline-more", inline)]
9196
fn drive_unindexed<C>(self, consumer: C) -> C::Result
9297
where
9398
C: UnindexedConsumer<Self::Item>,
@@ -118,6 +123,7 @@ struct ParDrainProducer<T> {
118123
impl<T: Send> UnindexedProducer for ParDrainProducer<T> {
119124
type Item = T;
120125

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

135+
#[cfg_attr(feature = "inline-more", inline)]
129136
fn fold_with<F>(mut self, mut folder: F) -> F
130137
where
131138
F: Folder<Self::Item>,
@@ -146,6 +153,7 @@ impl<T: Send> UnindexedProducer for ParDrainProducer<T> {
146153
}
147154

148155
impl<T> Drop for ParDrainProducer<T> {
156+
#[cfg_attr(feature = "inline-more", inline)]
149157
fn drop(&mut self) {
150158
// Drop all remaining elements
151159
if mem::needs_drop::<T>() {
@@ -160,19 +168,22 @@ impl<T> Drop for ParDrainProducer<T> {
160168

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

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

174184
/// Returns a parallel iterator which consumes all elements of a `RawTable`
175185
/// without freeing its memory allocation.
186+
#[cfg_attr(feature = "inline-more", inline)]
176187
pub fn par_drain(&mut self) -> RawParDrain<'_, T> {
177188
RawParDrain {
178189
table: NonNull::from(self),

src/external_trait_impls/rayon/set.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ where
214214
{
215215
/// Visits (potentially in parallel) the values representing the difference,
216216
/// i.e. the values that are in `self` but not in `other`.
217+
#[cfg_attr(feature = "inline-more", inline)]
217218
pub fn par_difference<'a>(&'a self, other: &'a Self) -> ParDifference<'a, T, S> {
218219
ParDifference { a: self, b: other }
219220
}
220221

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

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

236239
/// Visits (potentially in parallel) the values representing the union,
237240
/// i.e. all the values in `self` or `other`, without duplicates.
241+
#[cfg_attr(feature = "inline-more", inline)]
238242
pub fn par_union<'a>(&'a self, other: &'a Self) -> ParUnion<'a, T, S> {
239243
ParUnion { a: self, b: other }
240244
}
@@ -283,6 +287,7 @@ where
283287
{
284288
/// Consumes (potentially in parallel) all values in an arbitrary order,
285289
/// while preserving the set's allocated memory for reuse.
290+
#[cfg_attr(feature = "inline-more", inline)]
286291
pub fn par_drain(&mut self) -> ParDrain<'_, T, S> {
287292
ParDrain { set: self }
288293
}
@@ -292,6 +297,7 @@ impl<T: Send, S: Send> IntoParallelIterator for HashSet<T, S> {
292297
type Item = T;
293298
type Iter = IntoParIter<T, S>;
294299

300+
#[cfg_attr(feature = "inline-more", inline)]
295301
fn into_par_iter(self) -> Self::Iter {
296302
IntoParIter { set: self }
297303
}
@@ -301,6 +307,7 @@ impl<'a, T: Sync, S: Sync> IntoParallelIterator for &'a HashSet<T, S> {
301307
type Item = &'a T;
302308
type Iter = ParIter<'a, T, S>;
303309

310+
#[cfg_attr(feature = "inline-more", inline)]
304311
fn into_par_iter(self) -> Self::Iter {
305312
ParIter { set: self }
306313
}

src/external_trait_impls/serde.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod size_hint {
44
/// This presumably exists to prevent denial of service attacks.
55
///
66
/// Original discussion: https://github.com/serde-rs/serde/issues/1114.
7+
#[cfg_attr(feature = "inline-more", inline)]
78
pub(super) fn cautious(hint: Option<usize>) -> usize {
89
cmp::min(hint.unwrap_or(0), 4096)
910
}
@@ -26,6 +27,7 @@ mod map {
2627
V: Serialize,
2728
H: BuildHasher,
2829
{
30+
#[cfg_attr(feature = "inline-more", inline)]
2931
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
3032
where
3133
S: Serializer,
@@ -60,6 +62,7 @@ mod map {
6062
formatter.write_str("a map")
6163
}
6264

65+
#[cfg_attr(feature = "inline-more", inline)]
6366
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
6467
where
6568
A: MapAccess<'de>,
@@ -101,6 +104,7 @@ mod set {
101104
T: Serialize + Eq + Hash,
102105
H: BuildHasher,
103106
{
107+
#[cfg_attr(feature = "inline-more", inline)]
104108
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
105109
where
106110
S: Serializer,
@@ -133,6 +137,7 @@ mod set {
133137
formatter.write_str("a sequence")
134138
}
135139

140+
#[cfg_attr(feature = "inline-more", inline)]
136141
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
137142
where
138143
A: SeqAccess<'de>,
@@ -173,6 +178,7 @@ mod set {
173178
formatter.write_str("a sequence")
174179
}
175180

181+
#[cfg_attr(feature = "inline-more", inline)]
176182
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
177183
where
178184
A: SeqAccess<'de>,

0 commit comments

Comments
 (0)