Skip to content

Commit 0870a26

Browse files
committed
Improve runtime inlining slightly
1 parent 68c1c2c commit 0870a26

File tree

7 files changed

+78
-67
lines changed

7 files changed

+78
-67
lines changed

crates/objc2/src/runtime/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ impl UnwindSafe for Ivar {}
300300
impl RefUnwindSafe for Ivar {}
301301

302302
impl Ivar {
303+
#[inline]
303304
pub(crate) fn as_ptr(&self) -> *const ffi::objc_ivar {
304305
let ptr: *const Self = self;
305306
ptr.cast()
@@ -381,18 +382,21 @@ impl UnwindSafe for Method {}
381382
impl RefUnwindSafe for Method {}
382383

383384
impl Method {
385+
#[inline]
384386
pub(crate) fn as_ptr(&self) -> *const ffi::objc_method {
385387
let ptr: *const Self = self;
386388
ptr.cast()
387389
}
388390

389391
// Note: We don't take `&mut` here, since the operations on methods work
390392
// atomically.
393+
#[inline]
391394
pub(crate) fn as_mut_ptr(&self) -> *mut ffi::objc_method {
392395
self.as_ptr() as _
393396
}
394397

395398
/// Returns the name of self.
399+
#[inline]
396400
#[doc(alias = "method_getName")]
397401
pub fn name(&self) -> Sel {
398402
unsafe { Sel::from_ptr(ffi::method_getName(self.as_ptr())).unwrap() }
@@ -446,6 +450,7 @@ impl Method {
446450
}
447451

448452
/// Returns the number of arguments accepted by self.
453+
#[inline]
449454
#[doc(alias = "method_getNumberOfArguments")]
450455
pub fn arguments_count(&self) -> usize {
451456
unsafe { ffi::method_getNumberOfArguments(self.as_ptr()) as usize }
@@ -483,7 +488,6 @@ impl Method {
483488
///
484489
/// A common mistake would be expecting e.g. a pointer to not be null,
485490
/// where the null case was handled before.
486-
#[inline]
487491
#[doc(alias = "method_setImplementation")]
488492
pub unsafe fn set_implementation(&self, imp: Imp) -> Imp {
489493
// SAFETY: The new impl is not NULL, and the rest is upheld by the
@@ -574,6 +578,7 @@ impl RefUnwindSafe for AnyClass {}
574578
// Note that Unpin is not applicable.
575579

576580
impl AnyClass {
581+
#[inline]
577582
pub(crate) fn as_ptr(&self) -> *const ffi::objc_class {
578583
let ptr: *const Self = self;
579584
ptr.cast()
@@ -603,6 +608,7 @@ impl AnyClass {
603608
}
604609

605610
/// Returns the total number of registered classes.
611+
#[inline]
606612
#[doc(alias = "objc_getClassList")]
607613
pub fn classes_count() -> usize {
608614
unsafe { ffi::objc_getClassList(ptr::null_mut(), 0) as usize }
@@ -734,6 +740,7 @@ impl AnyClass {
734740
}
735741

736742
/// Checks whether this class conforms to the specified protocol.
743+
#[inline]
737744
#[doc(alias = "class_conformsToProtocol")]
738745
pub fn conforms_to(&self, proto: &AnyProtocol) -> bool {
739746
unsafe {
@@ -861,6 +868,7 @@ impl RefUnwindSafe for AnyProtocol {}
861868
// Note that Unpin is not applicable.
862869

863870
impl AnyProtocol {
871+
#[inline]
864872
pub(crate) fn as_ptr(&self) -> *const ffi::objc_protocol {
865873
let ptr: *const Self = self;
866874
ptr.cast()
@@ -901,6 +909,7 @@ impl AnyProtocol {
901909
}
902910

903911
/// Checks whether this protocol conforms to the specified protocol.
912+
#[inline]
904913
#[doc(alias = "protocol_conformsToProtocol")]
905914
pub fn conforms_to(&self, proto: &AnyProtocol) -> bool {
906915
unsafe {
@@ -1045,12 +1054,14 @@ unsafe impl RefEncode for AnyObject {
10451054
unsafe impl Message for AnyObject {}
10461055

10471056
impl AnyObject {
1057+
#[inline]
10481058
pub(crate) fn as_ptr(&self) -> *const ffi::objc_object {
10491059
let ptr: *const Self = self;
10501060
ptr.cast()
10511061
}
10521062

10531063
/// Dynamically find the class of this object.
1064+
#[inline]
10541065
#[doc(alias = "object_getClass")]
10551066
pub fn class(&self) -> &'static AnyClass {
10561067
let ptr: *const AnyClass = unsafe { ffi::object_getClass(self.as_ptr()) }.cast();

crates/test-assembly/crates/test_declare_class/expected/apple-aarch64.s

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ _access_ivars:
383383
add x29, sp, #32
384384
bl _get_obj
385385
mov x19, x0
386-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
386+
bl _object_getClass
387387
Lloh88:
388388
adrp x1, l_anon.[ID].11@PAGE
389389
Lloh89:
@@ -396,7 +396,7 @@ Lloh91:
396396
bl SYM(objc2::runtime::ivar_offset::GENERATED_ID, 0)
397397
ldrb w20, [x19, x0]
398398
mov x0, x19
399-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
399+
bl _object_getClass
400400
Lloh92:
401401
adrp x1, l_anon.[ID].13@PAGE
402402
Lloh93:
@@ -500,7 +500,7 @@ SYM(<test_declare_class[CRATE_ID]::Custom as objc2[CRATE_ID]::top_level_traits::
500500
add x29, sp, #32
501501
mov x19, x1
502502
mov x20, x0
503-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
503+
bl _object_getClass
504504
Lloh112:
505505
adrp x1, l_anon.[ID].13@PAGE
506506
Lloh113:
@@ -558,7 +558,7 @@ Lloh124:
558558
mov x19, x0
559559
cbz x0, LBB9_2
560560
mov x0, x19
561-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
561+
bl _object_getClass
562562
Lloh125:
563563
adrp x1, l_anon.[ID].11@PAGE
564564
Lloh126:
@@ -572,7 +572,7 @@ Lloh128:
572572
mov w8, #42
573573
strb w8, [x19, x0]
574574
mov x0, x19
575-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
575+
bl _object_getClass
576576
Lloh129:
577577
adrp x1, l_anon.[ID].13@PAGE
578578
Lloh130:
@@ -620,7 +620,7 @@ _method_id:
620620
stp x29, x30, [sp, #16]
621621
add x29, sp, #16
622622
mov x19, x0
623-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
623+
bl _object_getClass
624624
Lloh133:
625625
adrp x1, l_anon.[ID].13@PAGE
626626
Lloh134:
@@ -654,7 +654,7 @@ _method_id_with_param:
654654
mov x19, x0
655655
cbz w21, LBB14_5
656656
mov x0, x20
657-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
657+
bl _object_getClass
658658
Lloh137:
659659
adrp x1, l_anon.[ID].13@PAGE
660660
Lloh138:
@@ -698,7 +698,7 @@ _copyWithZone:
698698
mov x19, x0
699699
cbz x0, LBB15_5
700700
mov x0, x20
701-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
701+
bl _object_getClass
702702
Lloh141:
703703
adrp x21, l_anon.[ID].11@PAGE
704704
Lloh142:
@@ -713,14 +713,14 @@ Lloh144:
713713
bl SYM(objc2::runtime::ivar_offset::GENERATED_ID, 0)
714714
ldrb w23, [x20, x0]
715715
mov x0, x19
716-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
716+
bl _object_getClass
717717
mov x1, x21
718718
mov w2, #4
719719
mov x3, x22
720720
bl SYM(objc2::runtime::ivar_offset::GENERATED_ID, 0)
721721
strb w23, [x19, x0]
722722
mov x0, x20
723-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
723+
bl _object_getClass
724724
Lloh145:
725725
adrp x1, l_anon.[ID].13@PAGE
726726
Lloh146:
@@ -740,7 +740,7 @@ LBB15_3:
740740
mov x20, #0
741741
LBB15_4:
742742
mov x0, x19
743-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
743+
bl _object_getClass
744744
Lloh149:
745745
adrp x1, l_anon.[ID].13@PAGE
746746
Lloh150:

crates/test-assembly/crates/test_declare_class/expected/apple-armv7.s

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ _access_ivars:
344344
add r7, sp, #12
345345
bl _get_obj
346346
mov r4, r0
347-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
347+
bl _object_getClass
348348
movw r1, :lower16:(L_anon.[ID].11-(LPC6_0+8))
349349
mov r2, #4
350350
movt r1, :upper16:(L_anon.[ID].11-(LPC6_0+8))
@@ -357,7 +357,7 @@ LPC6_1:
357357
bl SYM(objc2::runtime::ivar_offset::GENERATED_ID, 0)
358358
ldrb r5, [r4, r0]
359359
mov r0, r4
360-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
360+
bl _object_getClass
361361
movw r1, :lower16:(L_anon.[ID].13-(LPC6_2+8))
362362
mov r2, #4
363363
movt r1, :upper16:(L_anon.[ID].13-(LPC6_2+8))
@@ -443,7 +443,7 @@ SYM(<test_declare_class[CRATE_ID]::Custom as objc2[CRATE_ID]::top_level_traits::
443443
sub sp, sp, #8
444444
mov r4, r1
445445
mov r5, r0
446-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
446+
bl _object_getClass
447447
movw r1, :lower16:(L_anon.[ID].13-(LPC8_0+8))
448448
mov r2, #4
449449
movt r1, :upper16:(L_anon.[ID].13-(LPC8_0+8))
@@ -496,7 +496,7 @@ LPC9_1:
496496
cmp r0, #0
497497
beq LBB9_2
498498
mov r0, r4
499-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
499+
bl _object_getClass
500500
movw r1, :lower16:(L_anon.[ID].11-(LPC9_2+8))
501501
mov r2, #4
502502
movt r1, :upper16:(L_anon.[ID].11-(LPC9_2+8))
@@ -510,7 +510,7 @@ LPC9_3:
510510
mov r1, #42
511511
strb r1, [r4, r0]
512512
mov r0, r4
513-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
513+
bl _object_getClass
514514
movw r1, :lower16:(L_anon.[ID].13-(LPC9_4+8))
515515
mov r2, #4
516516
movt r1, :upper16:(L_anon.[ID].13-(LPC9_4+8))
@@ -555,7 +555,7 @@ _method_id:
555555
push {r4, r7, lr}
556556
add r7, sp, #4
557557
mov r4, r0
558-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
558+
bl _object_getClass
559559
movw r1, :lower16:(L_anon.[ID].13-(LPC13_0+8))
560560
mov r2, #4
561561
movt r1, :upper16:(L_anon.[ID].13-(LPC13_0+8))
@@ -590,7 +590,7 @@ _method_id_with_param:
590590
cmp r6, #0
591591
beq LBB14_3
592592
mov r0, r5
593-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
593+
bl _object_getClass
594594
movw r1, :lower16:(L_anon.[ID].13-(LPC14_0+8))
595595
mov r2, #4
596596
movt r1, :upper16:(L_anon.[ID].13-(LPC14_0+8))
@@ -634,7 +634,7 @@ _copyWithZone:
634634
cmp r0, #0
635635
beq LBB15_5
636636
mov r0, r5
637-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
637+
bl _object_getClass
638638
movw r10, :lower16:(L_anon.[ID].11-(LPC15_0+8))
639639
mov r2, #4
640640
movt r10, :upper16:(L_anon.[ID].11-(LPC15_0+8))
@@ -649,14 +649,14 @@ LPC15_1:
649649
bl SYM(objc2::runtime::ivar_offset::GENERATED_ID, 0)
650650
ldrb r6, [r5, r0]
651651
mov r0, r4
652-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
652+
bl _object_getClass
653653
mov r1, r10
654654
mov r2, #4
655655
mov r3, r8
656656
bl SYM(objc2::runtime::ivar_offset::GENERATED_ID, 0)
657657
strb r6, [r4, r0]
658658
mov r0, r5
659-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
659+
bl _object_getClass
660660
movw r1, :lower16:(L_anon.[ID].13-(LPC15_2+8))
661661
mov r2, #4
662662
movt r1, :upper16:(L_anon.[ID].13-(LPC15_2+8))
@@ -677,7 +677,7 @@ LBB15_3:
677677
mov r5, #0
678678
LBB15_4:
679679
mov r0, r4
680-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
680+
bl _object_getClass
681681
movw r1, :lower16:(L_anon.[ID].13-(LPC15_4+8))
682682
mov r2, #4
683683
movt r1, :upper16:(L_anon.[ID].13-(LPC15_4+8))

crates/test-assembly/crates/test_declare_class/expected/apple-armv7s.s

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ _access_ivars:
347347
add r7, sp, #12
348348
bl _get_obj
349349
mov r4, r0
350-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
350+
bl _object_getClass
351351
movw r1, :lower16:(L_anon.[ID].11-(LPC6_0+8))
352352
mov r2, #4
353353
movt r1, :upper16:(L_anon.[ID].11-(LPC6_0+8))
@@ -360,7 +360,7 @@ LPC6_1:
360360
bl SYM(objc2::runtime::ivar_offset::GENERATED_ID, 0)
361361
ldrb r5, [r4, r0]
362362
mov r0, r4
363-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
363+
bl _object_getClass
364364
movw r1, :lower16:(L_anon.[ID].13-(LPC6_2+8))
365365
mov r2, #4
366366
movt r1, :upper16:(L_anon.[ID].13-(LPC6_2+8))
@@ -446,7 +446,7 @@ SYM(<test_declare_class[CRATE_ID]::Custom as objc2[CRATE_ID]::top_level_traits::
446446
sub sp, sp, #8
447447
mov r4, r1
448448
mov r5, r0
449-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
449+
bl _object_getClass
450450
movw r1, :lower16:(L_anon.[ID].13-(LPC8_0+8))
451451
mov r2, #4
452452
movt r1, :upper16:(L_anon.[ID].13-(LPC8_0+8))
@@ -499,7 +499,7 @@ LPC9_1:
499499
cmp r0, #0
500500
beq LBB9_2
501501
mov r0, r4
502-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
502+
bl _object_getClass
503503
movw r1, :lower16:(L_anon.[ID].11-(LPC9_2+8))
504504
mov r2, #4
505505
movt r1, :upper16:(L_anon.[ID].11-(LPC9_2+8))
@@ -513,7 +513,7 @@ LPC9_3:
513513
mov r1, #42
514514
strb r1, [r4, r0]
515515
mov r0, r4
516-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
516+
bl _object_getClass
517517
movw r1, :lower16:(L_anon.[ID].13-(LPC9_4+8))
518518
mov r2, #4
519519
movt r1, :upper16:(L_anon.[ID].13-(LPC9_4+8))
@@ -558,7 +558,7 @@ _method_id:
558558
push {r4, r7, lr}
559559
add r7, sp, #4
560560
mov r4, r0
561-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
561+
bl _object_getClass
562562
movw r1, :lower16:(L_anon.[ID].13-(LPC13_0+8))
563563
mov r2, #4
564564
movt r1, :upper16:(L_anon.[ID].13-(LPC13_0+8))
@@ -593,7 +593,7 @@ _method_id_with_param:
593593
cmp r6, #0
594594
beq LBB14_3
595595
mov r0, r5
596-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
596+
bl _object_getClass
597597
movw r1, :lower16:(L_anon.[ID].13-(LPC14_0+8))
598598
mov r2, #4
599599
movt r1, :upper16:(L_anon.[ID].13-(LPC14_0+8))
@@ -637,7 +637,7 @@ _copyWithZone:
637637
cmp r0, #0
638638
beq LBB15_5
639639
mov r0, r5
640-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
640+
bl _object_getClass
641641
movw r10, :lower16:(L_anon.[ID].11-(LPC15_0+8))
642642
mov r2, #4
643643
movt r10, :upper16:(L_anon.[ID].11-(LPC15_0+8))
@@ -652,14 +652,14 @@ LPC15_1:
652652
bl SYM(objc2::runtime::ivar_offset::GENERATED_ID, 0)
653653
ldrb r6, [r5, r0]
654654
mov r0, r4
655-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
655+
bl _object_getClass
656656
mov r1, r10
657657
mov r2, #4
658658
mov r3, r8
659659
bl SYM(objc2::runtime::ivar_offset::GENERATED_ID, 0)
660660
strb r6, [r4, r0]
661661
mov r0, r5
662-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
662+
bl _object_getClass
663663
movw r1, :lower16:(L_anon.[ID].13-(LPC15_2+8))
664664
mov r2, #4
665665
movt r1, :upper16:(L_anon.[ID].13-(LPC15_2+8))
@@ -680,7 +680,7 @@ LBB15_3:
680680
mov r5, #0
681681
LBB15_4:
682682
mov r0, r4
683-
bl SYM(objc2::runtime::AnyObject::class::GENERATED_ID, 0)
683+
bl _object_getClass
684684
movw r1, :lower16:(L_anon.[ID].13-(LPC15_4+8))
685685
mov r2, #4
686686
movt r1, :upper16:(L_anon.[ID].13-(LPC15_4+8))

0 commit comments

Comments
 (0)