|
241 | 241 | } |
242 | 242 |
|
243 | 243 | Strong<ObjCConstructorNative> TypeFactory::getObjCNativeConstructorByNativeName(GlobalObject* globalObject, |
244 | | - const WTF::String& klassName, |
| 244 | + Class klass, |
245 | 245 | const ProtocolMetas& protocols) { |
246 | | - const InterfaceMeta* metadata = MetaFile::instance()->globalTableNativeInterfaces()->findInterfaceMeta(klassName.impl()); |
| 246 | + |
| 247 | + if (ObjCConstructorNative* type = this->_cacheId.get(ConstructorKey(klass, protocols))) { |
| 248 | + return Strong<ObjCConstructorNative>(globalObject->vm(), type); |
| 249 | + } |
| 250 | + |
| 251 | + const InterfaceMeta* metadata = MetaFile::instance()->globalTableNativeInterfaces()->findInterfaceMeta(class_getName(klass)); |
247 | 252 | return this->getObjCNativeConstructor(globalObject, metadata, protocols); |
248 | 253 | } |
249 | 254 |
|
|
284 | 289 | Strong<ObjCConstructorNative> TypeFactory::getObjCNativeConstructor(GlobalObject* globalObject, const ConstructorKey& constructorKey, const InterfaceMeta* metadata, const tns::instrumentation::Frame& frame) { |
285 | 290 | assert(constructorKey.klasses.known); |
286 | 291 |
|
287 | | - // remove unnecessary protocols which the actual interface already conforms to |
288 | 292 | ConstructorKey dedupedKey(constructorKey.klasses); |
289 | | - auto protocolsSet = metadata->deepProtocolsSet(); |
290 | | - for (auto p : constructorKey.additionalProtocols) { |
291 | | - if (protocolsSet.count(p) == 0) { |
292 | | - dedupedKey.additionalProtocols.append(p); |
| 293 | + |
| 294 | + // remove unnecessary protocols which the actual interface already conforms to |
| 295 | + if (constructorKey.additionalProtocols.size()) { |
| 296 | + auto protocolsSet = metadata->deepProtocolsSet(); |
| 297 | + for (auto p : constructorKey.additionalProtocols) { |
| 298 | + if (protocolsSet.count(p) == 0) { |
| 299 | + dedupedKey.additionalProtocols.append(p); |
| 300 | + } |
293 | 301 | } |
294 | 302 | } |
295 | 303 |
|
|
322 | 330 | : class_getSuperclass(dedupedKey.klasses.known); |
323 | 331 |
|
324 | 332 | if (superClass) { |
325 | | - parentConstructor = getObjCNativeConstructorByNativeName(globalObject, class_getName(superClass), ProtocolMetas()).get(); |
| 333 | + parentConstructor = getObjCNativeConstructorByNativeName(globalObject, superClass, ProtocolMetas()).get(); |
326 | 334 | parentPrototype = parentConstructor.get(globalObject->globalExec(), vm.propertyNames->prototype); |
327 | 335 |
|
328 | 336 | /// If we have a super class which somehow references us, our constructor will already have been cached |
|
359 | 367 | return Strong<ObjCConstructorNative>(globalObject->vm(), this->_nsObjectConstructor.get()); |
360 | 368 | } |
361 | 369 |
|
362 | | - auto constructor = getObjCNativeConstructorByNativeName(globalObject, "NSObject"_s, ProtocolMetas()); |
| 370 | + auto constructor = getObjCNativeConstructorByNativeName(globalObject, [NSObject class], ProtocolMetas()); |
363 | 371 | this->_nsObjectConstructor.set(globalObject->vm(), this, constructor.get()); |
364 | 372 | return constructor; |
365 | 373 | } |
|
501 | 509 |
|
502 | 510 | case BinaryTypeEncodingType::IdEncoding: { |
503 | 511 | auto additionalProtocols = getProtocolMetas(typeEncoding->details.idDetails._protocols); |
504 | | - result = getObjCNativeConstructorByNativeName(globalObject, "NSObject", additionalProtocols); |
| 512 | + result = getObjCNativeConstructorByNativeName(globalObject, [NSObject class], additionalProtocols); |
505 | 513 | break; |
506 | 514 | } |
507 | 515 | case BinaryTypeEncodingType::ConstantArrayEncoding: { |
|
0 commit comments