リビジョン | 5bea331233ee467d81e296a8a504a707c4fa8d1f (tree) |
---|---|
日時 | 2019-09-12 06:19:01 |
作者 | Agustina Arzille <avarzille@rise...> |
コミッター | Agustina Arzille |
Fix key comparisons in table implementation
@@ -36,29 +36,6 @@ | ||
36 | 36 | return (idx * 2); |
37 | 37 | } |
38 | 38 | |
39 | -static inline bool | |
40 | -table_equal (interpreter *interp, const table *tp, | |
41 | - object k1, object k2) | |
42 | -{ | |
43 | - // We only need to save K1, since K2 is the caller-provided key. | |
44 | - valref tmp (interp, k1); | |
45 | - if (tp->cmpfct == UNBOUND) | |
46 | - return (equal (interp, k1, k2)); | |
47 | - | |
48 | - return (QP_CALL (interp, tp->cmpfct, k1, k2) != NIL); | |
49 | -} | |
50 | - | |
51 | -static inline uint32_t | |
52 | -table_hash (interpreter *interp, const table *tp, object key) | |
53 | -{ | |
54 | - if (tp->hashfct == UNBOUND) | |
55 | - return (xhash (interp, key)); | |
56 | - else if (!fixint_p (QP_CALL (interp, tp->hashfct, key))) | |
57 | - interp->raise ("type-error", "hash function did not return an integer"); | |
58 | - | |
59 | - return ((uint32_t)as_int (interp->retval)); | |
60 | -} | |
61 | - | |
62 | 39 | static const uint32_t SECONDARY_KEYS[] = { 2, 3, 5, 7 }; |
63 | 40 | static const int N_SECONDARY_KEYS = QP_NELEM (SECONDARY_KEYS); |
64 | 41 |
@@ -141,6 +118,32 @@ | ||
141 | 118 | return (interp->alval); |
142 | 119 | } |
143 | 120 | |
121 | +static inline bool | |
122 | +table_equal (interpreter *interp, const table *tp, | |
123 | + object k1, object k2) | |
124 | +{ | |
125 | + if (k1 == DELETED_KEY) | |
126 | + return (false); | |
127 | + | |
128 | + // We only need to save K1, since K2 is the caller-provided key. | |
129 | + valref tmp (interp, k1); | |
130 | + if (tp->cmpfct == UNBOUND) | |
131 | + return (equal (interp, k1, k2)); | |
132 | + | |
133 | + return (QP_CALL (interp, tp->cmpfct, k1, k2) != NIL); | |
134 | +} | |
135 | + | |
136 | +static inline uint32_t | |
137 | +table_hash (interpreter *interp, const table *tp, object key) | |
138 | +{ | |
139 | + if (tp->hashfct == UNBOUND) | |
140 | + return (xhash (interp, key)); | |
141 | + else if (!fixint_p (QP_CALL (interp, tp->hashfct, key))) | |
142 | + interp->raise ("type-error", "hash function did not return an integer"); | |
143 | + | |
144 | + return ((uint32_t)as_int (interp->retval)); | |
145 | +} | |
146 | + | |
144 | 147 | #ifndef QP_HAS_ATOMIC_CASX |
145 | 148 | |
146 | 149 | // Try to atomically set the key in the table vector. |