Skip to content

Commit

Permalink
Fix some bugs in class_getInstanceMethod()
Browse files Browse the repository at this point in the history
  • Loading branch information
theraven committed Jul 11, 2011
1 parent e69ed06 commit 219f921
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static Method class_getInstanceMethodNonrecursive(Class aClass, SEL aSelector)
for (int i=0 ; i<methods->count ; i++)
{
Method method = &methods->methods[i];
if (method->selector->name == aSelector->name)
if (method->selector->index == aSelector->index)
{
return method;
}
Expand Down Expand Up @@ -349,15 +349,25 @@ Method class_getInstanceMethod(Class aClass, SEL aSelector)
{
CHECK_ARG(aClass);
CHECK_ARG(aSelector);
// Do a dtable lookup to find out which class the method comes from.
struct objc_slot *slot = objc_get_slot(aClass, aSelector);
if (NULL == slot) { return NULL; }

// Now find the typed variant of the selector, with the correct types.
aSelector = slot->selector;

// Then do the slow lookup to find the method.
return class_getInstanceMethodNonrecursive(slot->owner, aSelector);
// If the class has a dtable installed, then we can use the fast path
if (classHasInstalledDtable(aClass))
{
// Do a dtable lookup to find out which class the method comes from.
struct objc_slot *slot = objc_get_slot(aClass->isa, aSelector);
if (NULL == slot) { return NULL; }

// Now find the typed variant of the selector, with the correct types.
aSelector = slot->selector;

// Then do the slow lookup to find the method.
return class_getInstanceMethodNonrecursive(slot->owner, aSelector);
}
Method m = class_getInstanceMethodNonrecursive(aClass, aSelector);
if (NULL != m)
{
return m;
}
return class_getInstanceMethod(class_getSuperclass(aClass), aSelector);
}

Method class_getClassMethod(Class aClass, SEL aSelector)
Expand Down

0 comments on commit 219f921

Please sign in to comment.