2 Copyright © 1997-98, The AROS Development Team. All rights reserved.
5 Desc: Demo of new OOP system
13 #include "sysdep/sysdep.h"
22 # define CallMethod(cl, o, msg) \
24 return ( cl->MTable[msg->MethodID].MethodFunc(cl, o, msg)); \
27 #endif /* DIRECT_LOOKUP */
29 /*********************** HASHED_METHODS ***************************/
33 /* Using for () below, take 5,915 s.
35 # define CallMethod(cl, o, msg) \
37 register struct MethodBucket *b; \
38 register ULONG mid = msg->MethodID; \
40 for (b = cl->HashTable[mid & cl->HashMask]; \
43 if (b->MethodID == mid) \
45 return (b->MethodFunc(b->mClass, o, msg)); \
53 /* Using while() takes 5,915 s (Same as above)
55 # define CallMethod(cl, o, msg) \
57 register struct MethodBucket *b; \
58 register ULONG mid = msg->MethodID; \
60 b = cl->HashTable[mid & cl->HashMask]; \
64 if (b->MethodID == mid) \
66 return (b->MethodFunc(b->mClass, o, msg)); \
75 /* Using if - goto: 5,78 s.
76 # define CallMethod(cl, o, msg) \
78 register struct MethodBucket *b; \
79 register ULONG mid = msg->MethodID; \
81 b = cl->HashTable[mid & cl->HashMask]; \
85 if (b->MethodID == mid) \
87 return (b->MethodFunc(b->mClass, o, msg)); \
97 /* Surprisingly, when avoiding to put methodid into
98 ** a separate var, it comes down to 5,109 s.
99 ** even if MethodID is used (at least) two times
102 # define CallMethod(cl, o, msg) \
104 register struct MethodBucket *b; \
106 b = cl->HashTable[((msg->MethodID >> NUM_METHOD_BITS) ^ msg->MethodID) & cl->HashMask]; \
110 if (b->MethodID == msg->MethodID) \
112 return (b->MethodFunc(b->mClass, o, msg)); \
121 #endif /* HASHED_METHODS */
124 /*********************** HASHED_IFS ***************************/
128 # define CallMethod(cl, o, msg) \
130 register struct InterfaceBucket *b; \
131 register ULONG mid = msg->MethodID; \
132 register ULONG ifid = mid >> NUM_METHOD_BITS; \
133 register struct IFMethod *method; \
135 mid &= METHOD_MASK; \
137 b = cl->HashTable[ifid & cl->HashMask]; \
140 if (b->InterfaceID == ifid) \
142 method = &(b->MethodTable[mid]); \
143 return (method->MethodFunc(method->mClass, o, msg)); \
150 #endif /* HASHED_IFS */
152 /*********************** HASHED_STRINGS ***************************/
153 #ifdef HASHED_STRINGS
154 # define CallMethod(cl, o, msg) \
156 register struct MethodBucket *b; ULONG val; \
157 register STRPTR str1 = (STRPTR)msg->MethodID; \
159 register STRPTR str2; \
160 for (i = 0, val = 0; (i < MAX_HASH_CHARS) && *str1; str1 ++) \
161 { val += *str1; i ++; } \
162 for (b = cl->HashTable[val & cl->HashMask]; \
165 str2 = (STRPTR)b->MethodID; \
166 str1 = (STRPTR)msg->MethodID; \
167 while ( (!(i = *str1 - *str2)) && *str1) \
168 { str1 ++; str2 ++; } \
170 return (b->MethodFunc(b->mClass, o, msg)); \
175 #endif /* HASHED_STRINGS */
176 IPTR
CoerceMethodA(Class
*cl
, Object
*o
, Msg msg
)
178 CallMethod(cl
, o
, msg
);
181 IPTR
DoMethodA(Object
*o
, Msg msg
)
183 register Class
*cl
= OCLASS(o
);
185 CallMethod(cl
, o
, msg
);
188 IPTR
DoSuperMethodA(Class
*cl
, Object
*o
, Msg msg
)
190 Class
*super
= cl
->SuperClass
;
191 CallMethod(super
, o
, msg
);