static void objc_updateDtableForClassContainingMethod(Method m) { Class nextClass = Nil; void *state = NULL; SEL sel = method_getName(m); while (Nil != (nextClass = objc_next_class(&state))) { if (class_getInstanceMethodNonrecursive(nextClass, sel) == m) { objc_update_dtable_for_class(nextClass); return; } } }
static void register_methods(struct objc_class *cls, struct objc_method_list *l) { if (NULL == l) { return; } // Replace the method names with selectors. objc_register_selectors_from_list(l); // Add the method list at the head of the list of lists. l->next = cls->methods; cls->methods = l; // Update the dtable to catch the new methods. // FIXME: We can make this more efficient by simply passing the new method // list to the dtable and telling it only to update those methods. objc_update_dtable_for_class(cls); }
IMP class_replaceMethod(Class cls, SEL name, IMP imp, const char *types) { if (Nil == cls) { return (IMP)0; } SEL sel = sel_registerTypedName_np(sel_getName(name), types); Method method = class_getInstanceMethodNonrecursive(cls, sel); if (method == NULL) { class_addMethod(cls, sel, imp, types); return NULL; } IMP old = (IMP)method->imp; method->imp = imp; if (objc_test_class_flag(cls, objc_class_flag_resolved)) { objc_update_dtable_for_class(cls); } return old; }