Skip to content
This repository was archived by the owner on Aug 10, 2021. It is now read-only.

Commit 62cccc5

Browse files
committed
Review fixes
1 parent 97487b2 commit 62cccc5

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

runtime/src/main/cpp/ObjCExport.mm

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ static void throwIfCantBeOverridden(Class clazz, const KotlinToObjCMethodAdapter
888888
supers.push_back(t);
889889
}
890890

891+
bool itableEqualsSuper = true;
892+
891893
auto addToITable = [&interfaceVTables](ClassId interfaceId, int methodIndex, VTableElement entry) {
892894
RuntimeAssert(interfaceId != kInvalidInterfaceId, "");
893895
auto interfaceVTableIt = interfaceVTables.find(interfaceId);
@@ -897,7 +899,18 @@ static void throwIfCantBeOverridden(Class clazz, const KotlinToObjCMethodAdapter
897899
interfaceVTable[methodIndex] = entry;
898900
};
899901

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+
901914
for (const TypeInfo* t : supers) {
902915
const ObjCTypeAdapter* typeAdapter = getTypeAdapter(t);
903916
if (typeAdapter == nullptr) continue;
@@ -924,17 +937,7 @@ static void throwIfCantBeOverridden(Class clazz, const KotlinToObjCMethodAdapter
924937

925938
if (superITable != nullptr) {
926939
// 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);
938941
}
939942

940943
for (int i = 0; i < typeAdapter->reverseAdapterNum; ++i) {
@@ -946,18 +949,9 @@ static void throwIfCantBeOverridden(Class clazz, const KotlinToObjCMethodAdapter
946949
RuntimeAssert(adapter->vtableIndex == -1, "");
947950

948951
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_].
950953
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);
961955
addToITable(adapter->interfaceId, adapter->itableIndex, adapter->kotlinImpl);
962956
}
963957
}

0 commit comments

Comments
 (0)