libextobjc icon indicating copy to clipboard operation
libextobjc copied to clipboard

Runtime classes enumeration

Open k06a opened this issue 9 years ago • 4 comments

@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 avatar May 31 '16 21:05 k06a

Or you are not filtering out NSProxy subclasses?

(lldb) p [NSProxy isProxy]
NO

k06a avatar May 31 '16 21:05 k06a

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) {
    ...
}

k06a avatar May 31 '16 22:05 k06a

NSObject subclasses can be proxies, though.

jspahrsummers avatar Jun 01 '16 09:06 jspahrsummers

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

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

k06a avatar Jun 04 '16 19:06 k06a