Skip to content

Commit 085d615

Browse files
committed
Use function pointers in *_with_context to encourage context passing over environment capture
1 parent f136bee commit 085d615

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/raw/mod.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
992992
&mut self,
993993
cx: &mut C,
994994
hash: u64,
995-
eq: impl Fn(&mut C, &T) -> bool,
995+
eq: fn(&mut C, &T) -> bool,
996996
) -> bool {
997997
// Avoid `Option::map` because it bloats LLVM IR.
998998
if let Some(bucket) = self.find_with_context(cx, hash, eq) {
@@ -1035,7 +1035,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
10351035
&mut self,
10361036
cx: &mut C,
10371037
hash: u64,
1038-
eq: impl Fn(&mut C, &T) -> bool,
1038+
eq: fn(&mut C, &T) -> bool,
10391039
) -> Option<T> {
10401040
// Avoid `Option::map` because it bloats LLVM IR.
10411041
match self.find_with_context(cx, hash, eq) {
@@ -1074,8 +1074,8 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
10741074

10751075
/// Shrinks the table to fit `max(self.len(), min_size)` elements.
10761076
#[cfg_attr(feature = "inline-more", inline)]
1077-
pub fn shrink_to(&mut self, min_size: usize, hasher: impl Fn(&T) -> u64) {
1078-
self.shrink_to_with_context(&mut (), min_size, |_, value| hasher(value));
1077+
pub fn shrink_to(&mut self, min_size: usize, mut hasher: impl Fn(&T) -> u64) {
1078+
self.shrink_to_with_context(&mut hasher, min_size, |hasher, value| hasher(value));
10791079
}
10801080

10811081
/// Shrinks the table to fit `max(self.len(), min_size)` elements.
@@ -1087,7 +1087,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
10871087
&mut self,
10881088
cx: &mut C,
10891089
min_size: usize,
1090-
hasher: impl Fn(&mut C, &T) -> u64,
1090+
hasher: fn(&mut C, &T) -> u64,
10911091
) {
10921092
// Calculate the minimal number of elements that we need to reserve
10931093
// space for.
@@ -1131,8 +1131,8 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
11311131
/// Ensures that at least `additional` items can be inserted into the table
11321132
/// without reallocation.
11331133
#[cfg_attr(feature = "inline-more", inline)]
1134-
pub fn reserve(&mut self, additional: usize, hasher: impl Fn(&T) -> u64) {
1135-
self.reserve_with_context(&mut (), additional, |_, value| hasher(value))
1134+
pub fn reserve(&mut self, additional: usize, mut hasher: impl Fn(&T) -> u64) {
1135+
self.reserve_with_context(&mut hasher, additional, |hasher, value| hasher(value))
11361136
}
11371137

11381138
/// Ensures that at least `additional` items can be inserted into the table
@@ -1145,7 +1145,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
11451145
&mut self,
11461146
cx: &mut C,
11471147
additional: usize,
1148-
hasher: impl Fn(&mut C, &T) -> u64,
1148+
hasher: fn(&mut C, &T) -> u64,
11491149
) {
11501150
if unlikely(additional > self.table.growth_left) {
11511151
// Avoid `Result::unwrap_or_else` because it bloats LLVM IR.
@@ -1164,9 +1164,9 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
11641164
pub fn try_reserve(
11651165
&mut self,
11661166
additional: usize,
1167-
hasher: impl Fn(&T) -> u64,
1167+
mut hasher: impl Fn(&T) -> u64,
11681168
) -> Result<(), TryReserveError> {
1169-
self.try_reserve_with_context(&mut (), additional, |_, value| hasher(value))
1169+
self.try_reserve_with_context(&mut hasher, additional, |hasher, value| hasher(value))
11701170
}
11711171

11721172
/// Tries to ensure that at least `additional` items can be inserted into
@@ -1179,7 +1179,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
11791179
&mut self,
11801180
cx: &mut C,
11811181
additional: usize,
1182-
hasher: impl Fn(&mut C, &T) -> u64,
1182+
hasher: fn(&mut C, &T) -> u64,
11831183
) -> Result<(), TryReserveError> {
11841184
if additional > self.table.growth_left {
11851185
self.reserve_rehash(cx, additional, hasher, Fallibility::Fallible)
@@ -1195,7 +1195,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
11951195
&mut self,
11961196
cx: &mut C,
11971197
additional: usize,
1198-
hasher: impl Fn(&mut C, &T) -> u64,
1198+
hasher: fn(&mut C, &T) -> u64,
11991199
fallibility: Fallibility,
12001200
) -> Result<(), TryReserveError> {
12011201
unsafe {
@@ -1233,7 +1233,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
12331233
&mut self,
12341234
cx: &mut C,
12351235
capacity: usize,
1236-
hasher: impl Fn(&mut C, &T) -> u64,
1236+
hasher: fn(&mut C, &T) -> u64,
12371237
fallibility: Fallibility,
12381238
) -> Result<(), TryReserveError> {
12391239
// SAFETY:
@@ -1356,17 +1356,17 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
13561356
pub fn find_or_find_insert_slot(
13571357
&mut self,
13581358
hash: u64,
1359-
mut eq: impl FnMut(&T) -> bool,
1359+
eq: impl FnMut(&T) -> bool,
13601360
hasher: impl Fn(&T) -> u64,
13611361
) -> Result<Bucket<T>, InsertSlot> {
13621362
// NB: Since `eq` is the only one which actually uses a mutable
13631363
// environment, it's the only one we need to explicitly pass around
13641364
// through the context.
13651365
self.find_or_find_insert_slot_with_context(
1366-
&mut eq,
1366+
&mut (eq, hasher),
13671367
hash,
1368-
|eq, value| eq(value),
1369-
|_, value| hasher(value),
1368+
|(eq, _), value| eq(value),
1369+
|(_, hasher), value| hasher(value),
13701370
)
13711371
}
13721372

@@ -1385,8 +1385,8 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
13851385
&mut self,
13861386
cx: &mut C,
13871387
hash: u64,
1388-
eq: impl Fn(&mut C, &T) -> bool,
1389-
hasher: impl Fn(&mut C, &T) -> u64,
1388+
eq: fn(&mut C, &T) -> bool,
1389+
hasher: fn(&mut C, &T) -> u64,
13901390
) -> Result<Bucket<T>, InsertSlot> {
13911391
self.reserve_with_context(cx, 1, hasher);
13921392

@@ -1433,7 +1433,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
14331433
&self,
14341434
cx: &mut C,
14351435
hash: u64,
1436-
eq: impl Fn(&mut C, &T) -> bool,
1436+
eq: fn(&mut C, &T) -> bool,
14371437
) -> Option<Bucket<T>> {
14381438
let result = self.table.find_inner(cx, hash, &|cx, index| unsafe {
14391439
eq(cx, self.bucket(index).as_ref())
@@ -1461,7 +1461,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
14611461
&self,
14621462
cx: &mut C,
14631463
hash: u64,
1464-
eq: impl Fn(&mut C, &T) -> bool,
1464+
eq: fn(&mut C, &T) -> bool,
14651465
) -> Option<&T> {
14661466
// Avoid `Option::map` because it bloats LLVM IR.
14671467
match self.find_with_context(cx, hash, eq) {
@@ -1485,7 +1485,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
14851485
&mut self,
14861486
cx: &mut C,
14871487
hash: u64,
1488-
eq: impl Fn(&mut C, &T) -> bool,
1488+
eq: fn(&mut C, &T) -> bool,
14891489
) -> Option<&mut T> {
14901490
// Avoid `Option::map` because it bloats LLVM IR.
14911491
match self.find_with_context(cx, hash, eq) {

0 commit comments

Comments
 (0)