@@ -55,7 +55,6 @@ extern crate std;
55
55
#[ cfg( test) ]
56
56
mod test_utils;
57
57
58
- use alloc:: boxed:: Box ;
59
58
use core:: ffi:: c_void;
60
59
use core:: marker:: PhantomData ;
61
60
use core:: mem;
@@ -349,7 +348,7 @@ concrete_block_impl!(
349
348
#[ repr( C ) ]
350
349
pub struct ConcreteBlock < A , R , F > {
351
350
base : BlockBase < A , R > ,
352
- descriptor : Box < BlockDescriptor < ConcreteBlock < A , R , F > > > ,
351
+ descriptor : * const BlockDescriptor < ConcreteBlock < A , R , F > > ,
353
352
closure : F ,
354
353
}
355
354
@@ -374,19 +373,25 @@ where
374
373
}
375
374
376
375
impl < A , R , F > ConcreteBlock < A , R , F > {
376
+ const DESCRIPTOR : BlockDescriptor < Self > = BlockDescriptor {
377
+ _reserved : 0 ,
378
+ block_size : mem:: size_of :: < Self > ( ) as c_ulong ,
379
+ copy_helper : block_context_copy :: < Self > ,
380
+ dispose_helper : block_context_dispose :: < Self > ,
381
+ } ;
382
+
377
383
/// Constructs a `ConcreteBlock` with the given invoke function and closure.
378
384
/// Unsafe because the caller must ensure the invoke function takes the
379
385
/// correct arguments.
380
386
unsafe fn with_invoke ( invoke : unsafe extern "C" fn ( * mut Self , ...) -> R , closure : F ) -> Self {
381
387
ConcreteBlock {
382
388
base : BlockBase {
383
389
isa : & ffi:: _NSConcreteStackBlock,
384
- // 1 << 25 = BLOCK_HAS_COPY_DISPOSE
385
- flags : 1 << 25 ,
390
+ flags : ffi:: BLOCK_HAS_COPY_DISPOSE ,
386
391
_reserved : 0 ,
387
392
invoke : mem:: transmute ( invoke) ,
388
393
} ,
389
- descriptor : Box :: new ( BlockDescriptor :: new ( ) ) ,
394
+ descriptor : & Self :: DESCRIPTOR ,
390
395
closure,
391
396
}
392
397
}
@@ -452,17 +457,6 @@ struct BlockDescriptor<B> {
452
457
dispose_helper : unsafe extern "C" fn ( & mut B ) ,
453
458
}
454
459
455
- impl < B > BlockDescriptor < B > {
456
- fn new ( ) -> BlockDescriptor < B > {
457
- BlockDescriptor {
458
- _reserved : 0 ,
459
- block_size : mem:: size_of :: < B > ( ) as c_ulong ,
460
- copy_helper : block_context_copy :: < B > ,
461
- dispose_helper : block_context_dispose :: < B > ,
462
- }
463
- }
464
- }
465
-
466
460
#[ cfg( test) ]
467
461
mod tests {
468
462
use super :: { ConcreteBlock , RcBlock } ;
0 commit comments