@@ -177,6 +177,7 @@ impl<T: Send, F: Fn() -> T> Pool<T, F> {
177
177
/// the value to go back into the pool) and then calling get again is
178
178
/// *not* guaranteed to return the same value received in the first `get`
179
179
/// call.
180
+ #[ inline]
180
181
pub fn get ( & self ) -> PoolGuard < ' _ , T , F > {
181
182
PoolGuard ( self . 0 . get ( ) )
182
183
}
@@ -200,6 +201,7 @@ impl<'a, T: Send, F: Fn() -> T> PoolGuard<'a, T, F> {
200
201
/// This circumvents the guard's `Drop` implementation. This can be useful
201
202
/// in circumstances where the automatic `Drop` results in poorer codegen,
202
203
/// such as calling non-inlined functions.
204
+ #[ inline]
203
205
pub fn put ( this : PoolGuard < ' _ , T , F > ) {
204
206
inner:: PoolGuard :: put ( this. 0 ) ;
205
207
}
@@ -208,12 +210,14 @@ impl<'a, T: Send, F: Fn() -> T> PoolGuard<'a, T, F> {
208
210
impl < ' a , T : Send , F : Fn ( ) -> T > core:: ops:: Deref for PoolGuard < ' a , T , F > {
209
211
type Target = T ;
210
212
213
+ #[ inline]
211
214
fn deref ( & self ) -> & T {
212
215
self . 0 . value ( )
213
216
}
214
217
}
215
218
216
219
impl < ' a , T : Send , F : Fn ( ) -> T > core:: ops:: DerefMut for PoolGuard < ' a , T , F > {
220
+ #[ inline]
217
221
fn deref_mut ( & mut self ) -> & mut T {
218
222
self . 0 . value_mut ( )
219
223
}
@@ -469,6 +473,7 @@ mod inner {
469
473
impl < T : Send , F : Fn ( ) -> T > Pool < T , F > {
470
474
/// Get a value from the pool. This may block if another thread is also
471
475
/// attempting to retrieve a value from the pool.
476
+ #[ inline]
472
477
pub ( super ) fn get ( & self ) -> PoolGuard < ' _ , T , F > {
473
478
// Our fast path checks if the caller is the thread that "owns"
474
479
// this pool. Or stated differently, whether it is the first thread
@@ -562,6 +567,7 @@ mod inner {
562
567
/// Puts a value back into the pool. Callers don't need to call this.
563
568
/// Once the guard that's returned by 'get' is dropped, it is put back
564
569
/// into the pool automatically.
570
+ #[ inline]
565
571
fn put_value ( & self , value : Box < T > ) {
566
572
let caller = THREAD_ID . with ( |id| * id) ;
567
573
let stack_id = caller % self . stacks . len ( ) ;
@@ -587,18 +593,21 @@ mod inner {
587
593
}
588
594
589
595
/// Create a guard that represents the special owned T.
596
+ #[ inline]
590
597
fn guard_owned ( & self , caller : usize ) -> PoolGuard < ' _ , T , F > {
591
598
PoolGuard { pool : self , value : Err ( caller) , discard : false }
592
599
}
593
600
594
601
/// Create a guard that contains a value from the pool's stack.
602
+ #[ inline]
595
603
fn guard_stack ( & self , value : Box < T > ) -> PoolGuard < ' _ , T , F > {
596
604
PoolGuard { pool : self , value : Ok ( value) , discard : false }
597
605
}
598
606
599
607
/// Create a guard that contains a value from the pool's stack with an
600
608
/// instruction to throw away the value instead of putting it back
601
609
/// into the pool.
610
+ #[ inline]
602
611
fn guard_stack_transient ( & self , value : Box < T > ) -> PoolGuard < ' _ , T , F > {
603
612
PoolGuard { pool : self , value : Ok ( value) , discard : true }
604
613
}
@@ -633,6 +642,7 @@ mod inner {
633
642
634
643
impl < ' a , T : Send , F : Fn ( ) -> T > PoolGuard < ' a , T , F > {
635
644
/// Return the underlying value.
645
+ #[ inline]
636
646
pub ( super ) fn value ( & self ) -> & T {
637
647
match self . value {
638
648
Ok ( ref v) => & * * v,
@@ -657,6 +667,7 @@ mod inner {
657
667
}
658
668
659
669
/// Return the underlying value as a mutable borrow.
670
+ #[ inline]
660
671
pub ( super ) fn value_mut ( & mut self ) -> & mut T {
661
672
match self . value {
662
673
Ok ( ref mut v) => & mut * * v,
@@ -681,6 +692,7 @@ mod inner {
681
692
}
682
693
683
694
/// Consumes this guard and puts it back into the pool.
695
+ #[ inline]
684
696
pub ( super ) fn put ( this : PoolGuard < ' _ , T , F > ) {
685
697
// Since this is effectively consuming the guard and putting the
686
698
// value back into the pool, there's no reason to run its Drop
@@ -729,6 +741,7 @@ mod inner {
729
741
}
730
742
731
743
impl < ' a , T : Send , F : Fn ( ) -> T > Drop for PoolGuard < ' a , T , F > {
744
+ #[ inline]
732
745
fn drop ( & mut self ) {
733
746
self . put_imp ( ) ;
734
747
}
@@ -806,6 +819,7 @@ mod inner {
806
819
impl < T : Send , F : Fn ( ) -> T > Pool < T , F > {
807
820
/// Get a value from the pool. This may block if another thread is also
808
821
/// attempting to retrieve a value from the pool.
822
+ #[ inline]
809
823
pub ( super ) fn get ( & self ) -> PoolGuard < ' _ , T , F > {
810
824
let mut stack = self . stack . lock ( ) ;
811
825
let value = match stack. pop ( ) {
@@ -815,6 +829,7 @@ mod inner {
815
829
PoolGuard { pool : self , value : Some ( value) }
816
830
}
817
831
832
+ #[ inline]
818
833
fn put ( & self , guard : PoolGuard < ' _ , T , F > ) {
819
834
let mut guard = core:: mem:: ManuallyDrop :: new ( guard) ;
820
835
if let Some ( value) = guard. value . take ( ) {
@@ -825,6 +840,7 @@ mod inner {
825
840
/// Puts a value back into the pool. Callers don't need to call this.
826
841
/// Once the guard that's returned by 'get' is dropped, it is put back
827
842
/// into the pool automatically.
843
+ #[ inline]
828
844
fn put_value ( & self , value : Box < T > ) {
829
845
let mut stack = self . stack . lock ( ) ;
830
846
stack. push ( value) ;
@@ -847,16 +863,19 @@ mod inner {
847
863
848
864
impl < ' a , T : Send , F : Fn ( ) -> T > PoolGuard < ' a , T , F > {
849
865
/// Return the underlying value.
866
+ #[ inline]
850
867
pub ( super ) fn value ( & self ) -> & T {
851
868
self . value . as_deref ( ) . unwrap ( )
852
869
}
853
870
854
871
/// Return the underlying value as a mutable borrow.
872
+ #[ inline]
855
873
pub ( super ) fn value_mut ( & mut self ) -> & mut T {
856
874
self . value . as_deref_mut ( ) . unwrap ( )
857
875
}
858
876
859
877
/// Consumes this guard and puts it back into the pool.
878
+ #[ inline]
860
879
pub ( super ) fn put ( this : PoolGuard < ' _ , T , F > ) {
861
880
// Since this is effectively consuming the guard and putting the
862
881
// value back into the pool, there's no reason to run its Drop
@@ -878,6 +897,7 @@ mod inner {
878
897
}
879
898
880
899
impl < ' a , T : Send , F : Fn ( ) -> T > Drop for PoolGuard < ' a , T , F > {
900
+ #[ inline]
881
901
fn drop ( & mut self ) {
882
902
self . put_imp ( ) ;
883
903
}
@@ -931,6 +951,7 @@ mod inner {
931
951
/// Lock this mutex and return a guard providing exclusive access to
932
952
/// `T`. This blocks if some other thread has already locked this
933
953
/// mutex.
954
+ #[ inline]
934
955
fn lock ( & self ) -> MutexGuard < ' _ , T > {
935
956
while self
936
957
. locked
@@ -963,18 +984,21 @@ mod inner {
963
984
impl < ' a , T > core:: ops:: Deref for MutexGuard < ' a , T > {
964
985
type Target = T ;
965
986
987
+ #[ inline]
966
988
fn deref ( & self ) -> & T {
967
989
self . data
968
990
}
969
991
}
970
992
971
993
impl < ' a , T > core:: ops:: DerefMut for MutexGuard < ' a , T > {
994
+ #[ inline]
972
995
fn deref_mut ( & mut self ) -> & mut T {
973
996
self . data
974
997
}
975
998
}
976
999
977
1000
impl < ' a , T > Drop for MutexGuard < ' a , T > {
1001
+ #[ inline]
978
1002
fn drop ( & mut self ) {
979
1003
// Drop means 'data' is no longer accessible, so we can unlock
980
1004
// the mutex.
0 commit comments