@@ -888,6 +888,8 @@ static void throwIfCantBeOverridden(Class clazz, const KotlinToObjCMethodAdapter
888
888
supers.push_back (t);
889
889
}
890
890
891
+ bool itableEqualsSuper = true ;
892
+
891
893
auto addToITable = [&interfaceVTables](ClassId interfaceId, int methodIndex, VTableElement entry) {
892
894
RuntimeAssert (interfaceId != kInvalidInterfaceId , " " );
893
895
auto interfaceVTableIt = interfaceVTables.find (interfaceId);
@@ -897,7 +899,18 @@ static void throwIfCantBeOverridden(Class clazz, const KotlinToObjCMethodAdapter
897
899
interfaceVTable[methodIndex] = entry;
898
900
};
899
901
900
- bool itableEqualsSuper = true ;
902
+ auto addITable = [&interfaceVTables, &itableEqualsSuper](ClassId interfaceId, int itableSize) {
903
+ RuntimeAssert (itableSize >= 0 , " " );
904
+ auto interfaceVTablesIt = interfaceVTables.find (interfaceId);
905
+ if (interfaceVTablesIt == interfaceVTables.end ()) {
906
+ itableEqualsSuper = false ;
907
+ interfaceVTables.emplace (interfaceId, KStdVector<VTableElement>(itableSize));
908
+ } else {
909
+ auto const & interfaceVTable = interfaceVTablesIt->second ;
910
+ RuntimeAssert (interfaceVTable.size () == static_cast <size_t >(itableSize), " " );
911
+ }
912
+ };
913
+
901
914
for (const TypeInfo* t : supers) {
902
915
const ObjCTypeAdapter* typeAdapter = getTypeAdapter (t);
903
916
if (typeAdapter == nullptr ) continue ;
@@ -924,17 +937,7 @@ static void throwIfCantBeOverridden(Class clazz, const KotlinToObjCMethodAdapter
924
937
925
938
if (superITable != nullptr ) {
926
939
// The interface vtable has to be created always in order for type checks to work.
927
- auto interfaceId = typeInfo->classId_ ;
928
- int interfaceVTableSize = typeAdapter->kotlinItableSize ;
929
- RuntimeAssert (interfaceVTableSize >= 0 , " " );
930
- auto interfaceVTablesIt = interfaceVTables.find (interfaceId);
931
- if (interfaceVTablesIt == interfaceVTables.end ()) {
932
- itableEqualsSuper = false ;
933
- interfaceVTables.emplace (interfaceId, KStdVector<VTableElement>(interfaceVTableSize));
934
- } else {
935
- auto const & interfaceVTable = interfaceVTablesIt->second ;
936
- RuntimeAssert (interfaceVTable.size () == static_cast <size_t >(interfaceVTableSize), " " );
937
- }
940
+ addITable (typeInfo->classId_ , typeAdapter->kotlinItableSize );
938
941
}
939
942
940
943
for (int i = 0 ; i < typeAdapter->reverseAdapterNum ; ++i) {
@@ -946,18 +949,9 @@ static void throwIfCantBeOverridden(Class clazz, const KotlinToObjCMethodAdapter
946
949
RuntimeAssert (adapter->vtableIndex == -1 , " " );
947
950
948
951
if (adapter->itableIndex != -1 && superITable != nullptr ) {
949
- // Because of fake overrides [adapter->interfaceId] might not be equal to [typeInfo->classId_].
952
+ // In general, [adapter->interfaceId] might not be equal to [typeInfo->classId_].
950
953
auto interfaceId = adapter->interfaceId ;
951
- int interfaceVTableSize = adapter->itableSize ;
952
- RuntimeAssert (interfaceVTableSize >= 0 , " " );
953
- auto interfaceVTablesIt = interfaceVTables.find (interfaceId);
954
- if (interfaceVTablesIt == interfaceVTables.end ()) {
955
- interfaceVTables.emplace (interfaceId, KStdVector<VTableElement>(interfaceVTableSize));
956
- } else {
957
- auto const & interfaceVTable = interfaceVTablesIt->second ;
958
- RuntimeAssert (interfaceVTable.size () == static_cast <size_t >(interfaceVTableSize), " " );
959
- }
960
-
954
+ addITable (interfaceId, adapter->itableSize );
961
955
addToITable (adapter->interfaceId , adapter->itableIndex , adapter->kotlinImpl );
962
956
}
963
957
}
0 commit comments