Skip to content

Commit

Permalink
Removed unnecessary comparisons against the class (emit less code tha…
Browse files Browse the repository at this point in the history
…t will be faster in the common case)
  • Loading branch information
rpetrich committed Jan 31, 2010
1 parent 42bb183 commit 9fcf2d0
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions CaptainHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,8 @@ typedef struct CHClassDeclaration_ CHClassDeclaration_;
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \
__attribute__((always_inline)) \
static inline void $ ## class_name ## _ ## name ## _register() { \
if (class_val) { \
sigdef; \
class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \
} \
sigdef; \
class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \
} \
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args)
#define CHMethod_super_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \
Expand Down Expand Up @@ -347,30 +345,26 @@ typedef struct CHClassDeclaration_ CHClassDeclaration_;
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \
__attribute__((always_inline)) \
static inline void $ ## class_name ## _ ## name ## _register() { \
if (class_val) { \
Method method = class_getInstanceMethod(class_val, @selector(sel)); \
if (method) { \
$ ## class_name ## _ ## name ## _super = (__typeof__($ ## class_name ## _ ## name ## _super))method_getImplementation(method); \
if (class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, method_getTypeEncoding(method))) { \
$ ## class_name ## _ ## name ## _super = &$ ## class_name ## _ ## name ## _closure; \
} else { \
method_setImplementation(method, (IMP)&$ ## class_name ## _ ## name ## _method); \
} \
Method method = class_getInstanceMethod(class_val, @selector(sel)); \
if (method) { \
$ ## class_name ## _ ## name ## _super = (__typeof__($ ## class_name ## _ ## name ## _super))method_getImplementation(method); \
if (class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, method_getTypeEncoding(method))) { \
$ ## class_name ## _ ## name ## _super = &$ ## class_name ## _ ## name ## _closure; \
} else { \
sigdef; \
class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \
method_setImplementation(method, (IMP)&$ ## class_name ## _ ## name ## _method); \
} \
} else { \
sigdef; \
class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \
} \
} \
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args)
#define CHMethod_new_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \
__attribute__((always_inline)) \
static inline void $ ## class_name ## _ ## name ## _register() { \
if (class_val) { \
sigdef; \
class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \
} \
sigdef; \
class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \
} \
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args)
#define CHMethod_super_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \
Expand All @@ -383,14 +377,12 @@ typedef struct CHClassDeclaration_ CHClassDeclaration_;
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \
__attribute__((always_inline)) \
static inline void $ ## class_name ## _ ## name ## _register() { \
if (class_val) { \
Method method = class_getInstanceMethod(class_val, @selector(sel)); \
$ ## class_name ## _ ## name ## _super = (__typeof__($ ## class_name ## _ ## name ## _super))method_getImplementation(method); \
if (class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, method_getTypeEncoding(method))) { \
$ ## class_name ## _ ## name ## _super = &$ ## class_name ## _ ## name ## _closure; \
} else { \
method_setImplementation(method, (IMP)&$ ## class_name ## _ ## name ## _method); \
} \
Method method = class_getInstanceMethod(class_val, @selector(sel)); \
$ ## class_name ## _ ## name ## _super = (__typeof__($ ## class_name ## _ ## name ## _super))method_getImplementation(method); \
if (class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, method_getTypeEncoding(method))) { \
$ ## class_name ## _ ## name ## _super = &$ ## class_name ## _ ## name ## _closure; \
} else { \
method_setImplementation(method, (IMP)&$ ## class_name ## _ ## name ## _method); \
} \
} \
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args)
Expand All @@ -399,11 +391,9 @@ typedef struct CHClassDeclaration_ CHClassDeclaration_;
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \
__attribute__((always_inline)) \
static inline void $ ## class_name ## _ ## name ## _register() { \
if (class_val) { \
Method method = class_getInstanceMethod(class_val, @selector(sel)); \
$ ## class_name ## _ ## name ## _super = (__typeof__($ ## class_name ## _ ## name ## _super))method_getImplementation(method); \
method_setImplementation(method, (IMP)&$ ## class_name ## _ ## name ## _method); \
} \
Method method = class_getInstanceMethod(class_val, @selector(sel)); \
$ ## class_name ## _ ## name ## _super = (__typeof__($ ## class_name ## _ ## name ## _super))method_getImplementation(method); \
method_setImplementation(method, (IMP)&$ ## class_name ## _ ## name ## _method); \
} \
static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args)
#endif
Expand Down

0 comments on commit 9fcf2d0

Please sign in to comment.