• R/O
  • SSH

quipu: Commit

quipu mercurial repository


Commit MetaInfo

Revisionc138f7e7d361095800eddec90753d12eb7e1a66e (tree)
Zeit2019-11-18 09:55:43
AutorAgustina Arzille <avarzille@rise...>
CommiterAgustina Arzille

Log Message

Rework method ordering by number of nils

Ändern Zusammenfassung

Diff

diff -r 1ff86990392f -r c138f7e7d361 function.cpp
--- a/function.cpp Thu Nov 14 16:11:32 2019 -0300
+++ b/function.cpp Mon Nov 18 00:55:43 2019 +0000
@@ -182,6 +182,25 @@
182182
183183 // Generic functions and methods.
184184
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+
185204 static inline int
186205 meth_cmptypes (interpreter *interp, object x, object y)
187206 {
@@ -201,21 +220,21 @@
201220 else if (*t1 == fixint (0))
202221 {
203222 if (rv < 0)
204- return (-1); // Cannot be compared.
223+ return (types_tiebreak (a1, a2));
205224
206225 rv = 1;
207226 }
208227 else if (*t2 == fixint (0))
209228 {
210229 if (rv > 0)
211- return (-1); // Cannot be compared.
230+ return (types_tiebreak (a1, a2));
212231
213232 rv = -1;
214233 }
215234 else if (subtype_p (*t1, *t2) == 1)
216235 {
217236 if (rv > 0)
218- return (-1);
237+ return (types_tiebreak (a1, a2));
219238
220239 rv = -1;
221240 *a2->data |= EXTRA_BIT;
@@ -223,11 +242,12 @@
223242 else if (subtype_p (*t2, *t1) == 1)
224243 {
225244 if (rv < 0)
226- return (-1);
245+ return (types_tiebreak (a1, a2));
227246
228247 rv = 1;
229248 }
230249 else
250+ // Unrelated types.
231251 return ((*a2->data & EXTRA_BIT) ? 1 : -1);
232252 }
233253
diff -r 1ff86990392f -r c138f7e7d361 symbol.cpp
--- a/symbol.cpp Thu Nov 14 16:11:32 2019 -0300
+++ b/symbol.cpp Mon Nov 18 00:55:43 2019 +0000
@@ -1036,10 +1036,7 @@
10361036
10371037 *ret = sp->value;
10381038 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))
10431040 break;
10441041
10451042 atomic_spin_nop ();
Show on old repository browser