quipu mercurial repository
Revision | c138f7e7d361095800eddec90753d12eb7e1a66e (tree) |
---|---|
Zeit | 2019-11-18 09:55:43 |
Autor | Agustina Arzille <avarzille@rise...> |
Commiter | Agustina Arzille |
Rework method ordering by number of nils
@@ -182,6 +182,25 @@ | ||
182 | 182 | |
183 | 183 | // Generic functions and methods. |
184 | 184 | |
185 | +static inline uint32_t | |
186 | +types_nnils (const array *ap) | |
187 | +{ | |
188 | + uint32_t ret = 0; | |
189 | + for (uint32_t i = 0; i < ap->len; ++i) | |
190 | + if (ap->data[i] == fixint (0)) | |
191 | + ++ret; | |
192 | + | |
193 | + return (ret); | |
194 | +} | |
195 | + | |
196 | +static inline int | |
197 | +types_tiebreak (const array *a1, const array *a2) | |
198 | +{ | |
199 | + if (!fct_p (*a1->data) || !fct_p (*a2->data)) | |
200 | + return (-1); | |
201 | + return (types_nnils (a1) > types_nnils (a2) ? 1 : -1); | |
202 | +} | |
203 | + | |
185 | 204 | static inline int |
186 | 205 | meth_cmptypes (interpreter *interp, object x, object y) |
187 | 206 | { |
@@ -201,21 +220,21 @@ | ||
201 | 220 | else if (*t1 == fixint (0)) |
202 | 221 | { |
203 | 222 | if (rv < 0) |
204 | - return (-1); // Cannot be compared. | |
223 | + return (types_tiebreak (a1, a2)); | |
205 | 224 | |
206 | 225 | rv = 1; |
207 | 226 | } |
208 | 227 | else if (*t2 == fixint (0)) |
209 | 228 | { |
210 | 229 | if (rv > 0) |
211 | - return (-1); // Cannot be compared. | |
230 | + return (types_tiebreak (a1, a2)); | |
212 | 231 | |
213 | 232 | rv = -1; |
214 | 233 | } |
215 | 234 | else if (subtype_p (*t1, *t2) == 1) |
216 | 235 | { |
217 | 236 | if (rv > 0) |
218 | - return (-1); | |
237 | + return (types_tiebreak (a1, a2)); | |
219 | 238 | |
220 | 239 | rv = -1; |
221 | 240 | *a2->data |= EXTRA_BIT; |
@@ -223,11 +242,12 @@ | ||
223 | 242 | else if (subtype_p (*t2, *t1) == 1) |
224 | 243 | { |
225 | 244 | if (rv < 0) |
226 | - return (-1); | |
245 | + return (types_tiebreak (a1, a2)); | |
227 | 246 | |
228 | 247 | rv = 1; |
229 | 248 | } |
230 | 249 | else |
250 | + // Unrelated types. | |
231 | 251 | return ((*a2->data & EXTRA_BIT) ? 1 : -1); |
232 | 252 | } |
233 | 253 |
@@ -1036,10 +1036,7 @@ | ||
1036 | 1036 | |
1037 | 1037 | *ret = sp->value; |
1038 | 1038 | call_n (interp, argc + 1 - has_dfl); |
1039 | - | |
1040 | - symbol *s2 = as_symbol (intern (interp, name, pkg)); | |
1041 | - if (s2 == sp && | |
1042 | - atomic_cas_bool ((atomic_t *)&sp->value, *ret, interp->retval)) | |
1039 | + if (atomic_cas_bool ((atomic_t *)&sp->value, *ret, interp->retval)) | |
1043 | 1040 | break; |
1044 | 1041 | |
1045 | 1042 | atomic_spin_nop (); |