File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -236,19 +236,21 @@ macro_rules! impl_smaller {
236236// Scratch space to bridge gap between pack_ints and pack_bytes.
237237// In theory, we could avoid this intermediate step, but it would result in a lot of generated code.
238238#[ cfg( feature = "std" ) ]
239- fn with_scratch < T > ( f : impl FnOnce ( & mut Vec < u8 > ) -> T ) -> T {
239+ fn with_scratch < T > ( mut f : impl FnMut ( & mut Vec < u8 > ) -> T ) -> T {
240240 thread_local ! {
241241 static SCRATCH : core:: cell:: RefCell <Vec <u8 >> = const { core:: cell:: RefCell :: new( Vec :: new( ) ) }
242242 }
243- SCRATCH . with ( |s| {
244- let s = & mut s. borrow_mut ( ) ;
245- s. clear ( ) ;
246- f ( s)
247- } )
243+ SCRATCH
244+ . try_with ( |s| {
245+ let s = & mut s. borrow_mut ( ) ;
246+ s. clear ( ) ;
247+ f ( s)
248+ } )
249+ . unwrap_or_else ( |_| f ( & mut Vec :: new ( ) ) )
248250}
249251// Resort to allocation.
250252#[ cfg( not( feature = "std" ) ) ]
251- fn with_scratch < T > ( f : impl FnOnce ( & mut Vec < u8 > ) -> T ) -> T {
253+ fn with_scratch < T > ( mut f : impl FnMut ( & mut Vec < u8 > ) -> T ) -> T {
252254 f ( & mut Vec :: new ( ) )
253255}
254256
You can’t perform that action at this time.
0 commit comments