jspahrsummers / libextobjc

A Cocoa library to extend the Objective-C programming language.
MIT License
4.53k stars 461 forks source link

Runtime classes enumeration #120

Open k06a opened 8 years ago

k06a commented 8 years ago

@jspahrsummers can you just tell me how this lines works https://github.com/jspahrsummers/libextobjc/blob/371b8da18f163a8f7f8925ad6d592d7b3b82ad05/extobjc/EXTRuntimeExtensions.m#L354

BOOL keep = YES;

if (keep)
    keep &= class_respondsToSelector(class, @selector(methodSignatureForSelector:));

if (keep) {
    if (class_respondsToSelector(class, @selector(isProxy)))
        keep &= ![class isProxy];
}

How do you call + (BOOL)isProxy, where this method is defined? But you only check that instances of class class responds to selector isProxy. Checking - (BOOL)isProxy but calling + (BOOL)isProxy?

k06a commented 8 years ago

Or you are not filtering out NSProxy subclasses?

(lldb) p [NSProxy isProxy]
NO
k06a commented 8 years ago

Just did some measures, looks like class_getSuperclass works a lot faster than class_respondsToSelector, this version of checking for NSObject subclass is a lot faster (more than 10x times):

Class superclass = class;
while (superclass && superclass != [NSObject class]) {
    superclass = class_getSuperclass(superclass);
}
if (superclass) {
    ...
}
jspahrsummers commented 8 years ago

NSObject subclasses can be proxies, though.

k06a commented 8 years ago

@jspahrsummers but shouldn't this code be like this?

if (!class_isMetaClass(class) &&
    class_respondsToSelector(class_getSuperclass(class), @selector(isProxy)))
{
    keep &= ![class isProxy];
}