Added basic implementation of destroying a GPT table: just delete the
[AROS.git] / test / OOPDemos / method.c
blob7761fe4e5e708b21df2396803885762d79ba56e4
1 /*
2 Copyright © 1997-98, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Demo of new OOP system
6 Lang: english
7 */
9 #include "types.h"
10 #include "oop.h"
11 #include "hash.h"
13 #include "sysdep/sysdep.h"
15 #define SDEBUG 0
16 #define DEBUG 0
17 #include "debug.h"
20 #ifdef DIRECT_LOOKUP
22 # define CallMethod(cl, o, msg) \
23 { \
24 return ( cl->MTable[msg->MethodID].MethodFunc(cl, o, msg)); \
27 #endif /* DIRECT_LOOKUP */
29 /*********************** HASHED_METHODS ***************************/
30 #ifdef HASHED_METHODS
33 /* Using for () below, take 5,915 s.
35 # define CallMethod(cl, o, msg) \
36 { \
37 register struct MethodBucket *b; \
38 register ULONG mid = msg->MethodID; \
40 for (b = cl->HashTable[mid & cl->HashMask]; \
41 b; b = b->Next) \
42 { \
43 if (b->MethodID == mid) \
44 { \
45 return (b->MethodFunc(b->mClass, o, msg)); \
46 } \
47 } \
48 return (NULL); \
53 /* Using while() takes 5,915 s (Same as above)
55 # define CallMethod(cl, o, msg) \
56 { \
57 register struct MethodBucket *b; \
58 register ULONG mid = msg->MethodID; \
60 b = cl->HashTable[mid & cl->HashMask]; \
62 while (b) \
63 { \
64 if (b->MethodID == mid) \
65 { \
66 return (b->MethodFunc(b->mClass, o, msg)); \
67 } \
68 b = b->Next; \
70 } \
71 return (NULL); \
75 /* Using if - goto: 5,78 s.
76 # define CallMethod(cl, o, msg) \
77 { \
78 register struct MethodBucket *b; \
79 register ULONG mid = msg->MethodID; \
81 b = cl->HashTable[mid & cl->HashMask]; \
82 loop: \
83 if (b) \
84 { \
85 if (b->MethodID == mid) \
86 { \
87 return (b->MethodFunc(b->mClass, o, msg)); \
88 } \
89 b = b->Next; \
90 goto loop; \
91 } \
92 return (NULL); \
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
100 ** pr. invocation.
102 # define CallMethod(cl, o, msg) \
104 register struct MethodBucket *b; \
106 b = cl->HashTable[((msg->MethodID >> NUM_METHOD_BITS) ^ msg->MethodID) & cl->HashMask]; \
107 loop: \
108 if (b) \
110 if (b->MethodID == msg->MethodID) \
112 return (b->MethodFunc(b->mClass, o, msg)); \
114 b = b->Next; \
115 goto loop; \
117 return (NULL); \
121 #endif /* HASHED_METHODS */
124 /*********************** HASHED_IFS ***************************/
125 #ifdef 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]; \
138 loop: if (b) \
140 if (b->InterfaceID == ifid) \
142 method = &(b->MethodTable[mid]); \
143 return (method->MethodFunc(method->mClass, o, msg)); \
145 b = b->Next; \
146 goto loop; \
148 return (NULL); \
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; \
158 register LONG i; \
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]; \
163 b; b = b->Next) \
165 str2 = (STRPTR)b->MethodID; \
166 str1 = (STRPTR)msg->MethodID; \
167 while ( (!(i = *str1 - *str2)) && *str1) \
168 { str1 ++; str2 ++; } \
169 if (!i) \
170 return (b->MethodFunc(b->mClass, o, msg)); \
172 return (NULL); \
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);