diff --git a/src/deemon/objects/roset.c b/src/deemon/objects/roset.c index 29a0fb7dd..b1ee52ff6 100644 --- a/src/deemon/objects/roset.c +++ b/src/deemon/objects/roset.c @@ -405,9 +405,9 @@ roset_iter(RoSet *__restrict self) { return result; } -PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL +PRIVATE WUNUSED NONNULL((1)) size_t DCALL roset_size(RoSet *__restrict self) { - return DeeInt_NewSize(self->rs_size); + return self->rs_size; } PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL @@ -529,17 +529,48 @@ PRIVATE struct type_cmp roset_cmp = { }; PRIVATE struct type_seq roset_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&roset_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&roset_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&roset_contains, - /* .tp_getitem = */ NULL, - /* .tp_delitem = */ NULL, - /* .tp_setitem = */ NULL, - /* .tp_getrange = */ NULL, - /* .tp_delrange = */ NULL, - /* .tp_setrange = */ NULL, - /* .tp_nsi = */ NULL, - /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&roset_foreach, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&roset_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&roset_contains, + /* .tp_getitem = */ NULL, + /* .tp_delitem = */ NULL, + /* .tp_setitem = */ NULL, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ NULL, + /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&roset_foreach, + /* .tp_foreach_pair = */ NULL, + /* .tp_bounditem = */ NULL, + /* .tp_hasitem = */ NULL, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&roset_size, + /* .tp_size_fast = */ (size_t (DCALL *)(DeeObject *__restrict))&roset_size, + /* .tp_getitem_index = */ NULL, + /* .tp_getitem_index_fast = */ NULL, + /* .tp_delitem_index = */ NULL, + /* .tp_setitem_index = */ NULL, + /* .tp_bounditem_index = */ NULL, + /* .tp_hasitem_index = */ NULL, + /* .tp_getrange_index = */ NULL, + /* .tp_delrange_index = */ NULL, + /* .tp_setrange_index = */ NULL, + /* .tp_getrange_index_n = */ NULL, + /* .tp_delrange_index_n = */ NULL, + /* .tp_setrange_index_n = */ NULL, + /* .tp_trygetitem = */ NULL, + /* .tp_trygetitem_index = */ NULL, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL diff --git a/src/deemon/objects/set.c b/src/deemon/objects/set.c index ad80ad0a7..dfea5a300 100644 --- a/src/deemon/objects/set.c +++ b/src/deemon/objects/set.c @@ -193,12 +193,14 @@ invset_printrepr(DeeSetInversionObject *__restrict self, return DeeFormat_Printf(printer, arg, "~%r", self->si_set); } +#ifndef CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL invset_iterself(DeeSetInversionObject *__restrict self) { /* Sorry, but it's impossible to enumerate a set containing (almost) everything */ err_unimplemented_operator(Dee_TYPE(self), OPERATOR_ITER); return NULL; } +#endif /* !CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS */ PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL invset_tpcontains(DeeSetInversionObject *self, DeeObject *key) { @@ -211,7 +213,11 @@ invset_tpcontains(DeeSetInversionObject *self, DeeObject *key) { } PRIVATE struct type_seq invset_seq = { +#ifdef CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS + /* .tp_iter = */ NULL, +#else /* CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS */ /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&invset_iterself, +#endif /* !CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS */ /* .tp_sizeob = */ NULL, /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&invset_tpcontains, /* .tp_getitem = */ NULL, diff --git a/src/deemon/runtime/operator_info.c b/src/deemon/runtime/operator_info.c index b38c68832..742c917d6 100644 --- a/src/deemon/runtime/operator_info.c +++ b/src/deemon/runtime/operator_info.c @@ -2052,6 +2052,7 @@ PRIVATE struct type_seq to_seq = { /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&to_iter, /* .tp_sizeob = */ NULL, /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&to_contains + /* TODO: tp_foreach */ }; PRIVATE struct type_member tpconst to_class_members[] = { diff --git a/src/dex/collections/bitset.c b/src/dex/collections/bitset.c index c2a23f9fc..a4fd9be23 100644 --- a/src/dex/collections/bitset.c +++ b/src/dex/collections/bitset.c @@ -39,10 +39,14 @@ #include #include +#include #include #include +#undef SSIZE_MAX +#define SSIZE_MAX __SSIZE_MAX__ + /* Use to implement atomic bitset ops (so they're faster under CONFIG_NO_THREADS) */ #undef __hybrid_bitset_atomic_set #undef __hybrid_bitset_atomic_clear @@ -245,7 +249,7 @@ struct bitset_fromseq_data { * # of bits is stored in `bsfsd_bitset->bs_nbits') */ }; -PRIVATE WUNUSED NONNULL((2)) dssize_t DCALL +PRIVATE WUNUSED NONNULL((2)) Dee_ssize_t DCALL bitset_fromseq_cb(void *cookie, DeeObject *item) { struct bitset_fromseq_data *me = (struct bitset_fromseq_data *)cookie; DREF Bitset *bitset; @@ -329,7 +333,7 @@ bs_init_fromseq(DeeObject *seq, DeeObject *minbits_ob) { PRIVATE WUNUSED NONNULL((1)) size_t DCALL -bs_nsi_getsize(Bitset *__restrict self) { +bs_size(Bitset *__restrict self) { return bitset_popcount(self->bs_bitset, self->bs_nbits); } @@ -646,11 +650,6 @@ bs_iter(Bitset *__restrict self) { return NULL; } -PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -bs_size(Bitset *__restrict self) { - return DeeInt_NewSize(bs_nsi_getsize(self)); -} - PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL bs_contains(Bitset *self, DeeObject *key) { size_t bitno; @@ -662,27 +661,36 @@ bs_contains(Bitset *self, DeeObject *key) { return NULL; } +PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL +bs_getitem_index(Bitset *self, size_t bitno) { + if unlikely(bitno >= self->bs_nbits) + goto err_too_large; + return_bool(bitset_test(self->bs_bitset, bitno)); +err_too_large: + bs_err_bad_index(self, bitno); + return NULL; +} + +PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL +bs_trygetitem_index(Bitset *self, size_t bitno) { + if unlikely(bitno >= self->bs_nbits) + return ITER_DONE; + return_bool(bitset_test(self->bs_bitset, bitno)); +} + PRIVATE WUNUSED NONNULL((1)) int DCALL -bs_delitem(Bitset *self, DeeObject *key) { - size_t bitno; - if (DeeObject_AsSize(key, &bitno)) - goto err; +bs_delitem_index(Bitset *self, size_t bitno) { if unlikely(bitno >= self->bs_nbits) goto err_too_large; bitset_atomic_clear(self->bs_bitset, bitno); return 0; err_too_large: return bs_err_bad_index(self, bitno); -err: - return -1; } -PRIVATE WUNUSED NONNULL((1)) int DCALL -bs_setitem(Bitset *self, DeeObject *key, DeeObject *value) { +PRIVATE WUNUSED NONNULL((1, 3)) int DCALL +bs_setitem_index(Bitset *self, size_t bitno, DeeObject *value) { int temp; - size_t bitno; - if (DeeObject_AsSize(key, &bitno)) - goto err; if unlikely(bitno >= self->bs_nbits) goto err_too_large; temp = DeeObject_Bool(value); @@ -701,7 +709,7 @@ bs_setitem(Bitset *self, DeeObject *key, DeeObject *value) { } PRIVATE WUNUSED NONNULL((1)) DREF BitsetView *DCALL -bs_getrange_i(Bitset *self, dssize_t start, dssize_t end) { +bs_getrange_index(Bitset *self, Dee_ssize_t start, Dee_ssize_t end) { struct Dee_seq_range range; DREF BitsetView *result; result = DeeObject_MALLOC(BitsetView); @@ -725,48 +733,46 @@ bs_getrange_i(Bitset *self, dssize_t start, dssize_t end) { } PRIVATE WUNUSED NONNULL((1)) DREF BitsetView *DCALL -bs_getrange(Bitset *self, DeeObject *start, DeeObject *end) { - Dee_ssize_t start_i, end_i = self->bs_nbits; - if (DeeObject_AsSSize(start, &start_i)) +bs_getrange_index_n(Bitset *self, Dee_ssize_t start) { + DREF BitsetView *result; + result = DeeObject_MALLOC(BitsetView); + if unlikely(!result) goto err; - if (!DeeNone_Check(end)) { - if (DeeObject_AsSSize(end, &end_i)) - goto err; - } - return bs_getrange_i(self, start_i, end_i); + result->bsv_owner = (DREF DeeObject *)self; + Dee_Incref(self); + result->bsv_buf.bb_base = self->bs_bitset; + result->bsv_buf.bb_size = BITSET_SIZEOF(self->bs_nbits); +#ifndef __INTELLISENSE__ + result->bsv_buf.bb_put = NULL; +#endif /* !__INTELLISENSE__ */ + result->bsv_startbit = DeeSeqRange_Clamp_n(start, self->bs_nbits); + result->bsv_endbit = self->bs_nbits; + result->bsv_bflags = Dee_BUFFER_FWRITABLE; + DeeObject_Init(result, &BitsetView_Type); + return result; err: return NULL; } PRIVATE WUNUSED NONNULL((1)) int DCALL -bs_delrange(Bitset *self, DeeObject *start, DeeObject *end) { +bs_delrange_index(Bitset *self, Dee_ssize_t start, Dee_ssize_t end) { struct Dee_seq_range range; - Dee_ssize_t start_i, end_i = self->bs_nbits; - if (DeeObject_AsSSize(start, &start_i)) - goto err; - if (!DeeNone_Check(end)) { - if (DeeObject_AsSSize(end, &end_i)) - goto err; - } - DeeSeqRange_Clamp(&range, start_i, end_i, self->bs_nbits); + DeeSeqRange_Clamp(&range, start, end, self->bs_nbits); bitset_nclear(self->bs_bitset, range.sr_start, range.sr_end); return 0; -err: - return -1; } -PRIVATE WUNUSED NONNULL((1, 2, 3, 4)) int DCALL -bs_setrange(Bitset *self, DeeObject *start, - DeeObject *end, DeeObject *value) { - Dee_ssize_t start_i, end_i = self->bs_nbits; +PRIVATE WUNUSED NONNULL((1)) int DCALL +bs_delrange_index_n(Bitset *self, Dee_ssize_t start) { + size_t used_start = DeeSeqRange_Clamp_n(start, self->bs_nbits); + bitset_nclear(self->bs_bitset, used_start, self->bs_nbits); + return 0; +} + +PRIVATE WUNUSED NONNULL((1, 4)) int DCALL +bs_setrange_index(Bitset *self, Dee_ssize_t start, Dee_ssize_t end, DeeObject *value) { struct Dee_seq_range range; - if (DeeObject_AsSSize(start, &start_i)) - goto err; - if (!DeeNone_Check(end)) { - if (DeeObject_AsSSize(end, &end_i)) - goto err; - } - DeeSeqRange_Clamp(&range, start_i, end_i, self->bs_nbits); + DeeSeqRange_Clamp(&range, start, end, self->bs_nbits); if (DeeBool_Check(value)) { if (DeeBool_IsTrue(value)) { bitset_nset(self->bs_bitset, range.sr_start, range.sr_end); @@ -800,6 +806,11 @@ bs_setrange(Bitset *self, DeeObject *start, return -1; } +PRIVATE WUNUSED NONNULL((1, 3)) int DCALL +bs_setrange_index_n(Bitset *self, Dee_ssize_t start, DeeObject *value) { + return bs_setrange_index(self, start, SSIZE_MAX, value); +} + PRIVATE WUNUSED NONNULL((1, 2)) int DCALL bs_getbuf(Bitset *__restrict self, DeeBuffer *__restrict info, @@ -1516,11 +1527,11 @@ bs_bool(Bitset *__restrict self) { return bitset_anyset(self->bs_bitset, self->bs_nbits) ? 1 : 0; } -PRIVATE WUNUSED NONNULL((1)) dssize_t DCALL +PRIVATE WUNUSED NONNULL((1)) Dee_ssize_t DCALL bs_printrepr(Bitset *__restrict self, dformatprinter printer, void *arg) { bool is_first; size_t bitno; - dssize_t temp, result; + Dee_ssize_t temp, result; result = DeeFormat_PRINT(printer, arg, "Bitset({"); if unlikely(result < 0) goto done; @@ -1542,7 +1553,7 @@ bs_printrepr(Bitset *__restrict self, dformatprinter printer, void *arg) { PRIVATE WUNUSED NONNULL((1, 2)) Dee_ssize_t DCALL bs_foreach(Bitset *self, Dee_foreach_t proc, void *arg) { - dssize_t temp, result = 0; + Dee_ssize_t temp, result = 0; size_t bitno; bitset_foreach (bitno, self->bs_bitset, self->bs_nbits) { DREF DeeObject *id; @@ -1568,7 +1579,7 @@ PRIVATE struct type_nsi tpconst bs_nsi = { /* .nsi_flags = */ TYPE_SEQX_FMUTABLE | TYPE_SEQX_FRESIZABLE, { /* .nsi_setlike = */ { - /* .nsi_getsize = */ (dfunptr_t)&bs_nsi_getsize, + /* .nsi_getsize = */ (dfunptr_t)&bs_size, /* .nsi_insert = */ (dfunptr_t)&bs_nsi_insert, /* .nsi_remove = */ (dfunptr_t)&bs_nsi_remove, } @@ -1621,17 +1632,48 @@ PRIVATE struct type_cmp bs_cmp = { }; PRIVATE struct type_seq bs_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&bs_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&bs_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&bs_contains, - /* .tp_getitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&bs_contains, - /* .tp_delitem = */ (int (DCALL *)(DeeObject *, DeeObject *))&bs_delitem, - /* .tp_setitem = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))&bs_setitem, - /* .tp_getrange = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *, DeeObject *))&bs_getrange, - /* .tp_delrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))&bs_delrange, - /* .tp_setrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *, DeeObject *))&bs_setrange, - /* .tp_nsi = */ &bs_nsi, - /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&bs_foreach, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&bs_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&bs_contains, + /* .tp_getitem = */ NULL, + /* .tp_delitem = */ NULL, + /* .tp_setitem = */ NULL, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ &bs_nsi, + /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&bs_foreach, + /* .tp_foreach_pair = */ NULL, + /* .tp_bounditem = */ NULL, + /* .tp_hasitem = */ NULL, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&bs_size, + /* .tp_size_fast = */ NULL, + /* .tp_getitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&bs_getitem_index, + /* .tp_getitem_index_fast = */ NULL, + /* .tp_delitem_index = */ (int (DCALL *)(DeeObject *, size_t))&bs_delitem_index, + /* .tp_setitem_index = */ (int (DCALL *)(DeeObject *, size_t, DeeObject *))&bs_setitem_index, + /* .tp_bounditem_index = */ NULL, + /* .tp_hasitem_index = */ NULL, + /* .tp_getrange_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t))&bs_getrange_index, + /* .tp_delrange_index = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t))&bs_delrange_index, + /* .tp_setrange_index = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t, DeeObject *))&bs_setrange_index, + /* .tp_getrange_index_n = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t))&bs_getrange_index_n, + /* .tp_delrange_index_n = */ (int (DCALL *)(DeeObject *, Dee_ssize_t))&bs_delrange_index_n, + /* .tp_setrange_index_n = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, DeeObject *))&bs_setrange_index_n, + /* .tp_trygetitem = */ NULL, + /* .tp_trygetitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&bs_trygetitem_index, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; PRIVATE struct type_buffer bs_buffer = { @@ -1943,7 +1985,7 @@ INTERN DeeTypeObject Bitset_Type = { /* .tp_repr = */ NULL, /* .tp_bool = */ (int (DCALL *)(DeeObject *__restrict))&bs_bool, /* .tp_print = */ NULL, - /* .tp_printrepr = */ (dssize_t (DCALL *)(DeeObject *__restrict, Dee_formatprinter_t, void *))&bs_printrepr, + /* .tp_printrepr = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_formatprinter_t, void *))&bs_printrepr, }, /* .tp_call = */ NULL, /* .tp_visit = */ NULL, @@ -1974,7 +2016,7 @@ INTERN DeeTypeObject Bitset_Type = { -#define robs_nsi_getsize bs_nsi_getsize +#define robs_nsi_getsize bs_size #define robs_hash bs_hash PRIVATE WUNUSED NONNULL((1)) DREF Bitset *DCALL @@ -2033,19 +2075,21 @@ robs_init_fromseq_or_bitset(DeeObject *seq) { #define robs_or bs_or #define robs_xor bs_xor -#define robs_eq bs_eq -#define robs_ne bs_ne -#define robs_le bs_le -#define robs_ge bs_ge -#define robs_gr bs_gr -#define robs_lo bs_lo -#define robs_iter bs_iter -#define robs_size bs_size -#define robs_contains bs_contains -#define robs_foreach bs_foreach +#define robs_eq bs_eq +#define robs_ne bs_ne +#define robs_le bs_le +#define robs_ge bs_ge +#define robs_gr bs_gr +#define robs_lo bs_lo +#define robs_iter bs_iter +#define robs_size bs_size +#define robs_contains bs_contains +#define robs_foreach bs_foreach +#define robs_getitem_index bs_getitem_index +#define robs_trygetitem_index bs_trygetitem_index PRIVATE WUNUSED NONNULL((1)) DREF BitsetView *DCALL -robs_getrange_i(Bitset *self, dssize_t start, dssize_t end) { +robs_getrange_index(Bitset *self, Dee_ssize_t start, Dee_ssize_t end) { struct Dee_seq_range range; DREF BitsetView *result; result = DeeObject_MALLOC(BitsetView); @@ -2069,15 +2113,23 @@ robs_getrange_i(Bitset *self, dssize_t start, dssize_t end) { } PRIVATE WUNUSED NONNULL((1)) DREF BitsetView *DCALL -robs_getrange(Bitset *self, DeeObject *start, DeeObject *end) { - Dee_ssize_t start_i, end_i = self->bs_nbits; - if (DeeObject_AsSSize(start, &start_i)) +robs_getrange_index_n(Bitset *self, Dee_ssize_t start) { + DREF BitsetView *result; + result = DeeObject_MALLOC(BitsetView); + if unlikely(!result) goto err; - if (!DeeNone_Check(end)) { - if (DeeObject_AsSSize(end, &end_i)) - goto err; - } - return robs_getrange_i(self, start_i, end_i); + result->bsv_owner = (DREF DeeObject *)self; + Dee_Incref(self); + result->bsv_buf.bb_base = self->bs_bitset; + result->bsv_buf.bb_size = BITSET_SIZEOF(self->bs_nbits); +#ifndef __INTELLISENSE__ + result->bsv_buf.bb_put = NULL; +#endif /* !__INTELLISENSE__ */ + result->bsv_startbit = DeeSeqRange_Clamp_n(start, self->bs_nbits); + result->bsv_endbit = self->bs_nbits; + result->bsv_bflags = Dee_BUFFER_FREADONLY; + DeeObject_Init(result, &BitsetView_Type); + return result; err: return NULL; } @@ -2133,11 +2185,11 @@ robs_init(size_t argc, DeeObject *const *argv) { #define robs_bool bs_bool -PRIVATE WUNUSED NONNULL((1)) dssize_t DCALL +PRIVATE WUNUSED NONNULL((1)) Dee_ssize_t DCALL robs_printrepr(Bitset *__restrict self, dformatprinter printer, void *arg) { bool is_first; size_t bitno; - dssize_t temp, result; + Dee_ssize_t temp, result; result = DeeFormat_PRINT(printer, arg, "Bitset.Frozen({"); if unlikely(result < 0) goto done; @@ -2216,17 +2268,48 @@ PRIVATE struct type_cmp robs_cmp = { }; PRIVATE struct type_seq robs_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&robs_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&robs_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&robs_contains, - /* .tp_getitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&robs_contains, - /* .tp_delitem = */ NULL, - /* .tp_setitem = */ NULL, - /* .tp_getrange = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *, DeeObject *))&robs_getrange, - /* .tp_delrange = */ NULL, - /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &robs_nsi, - /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&robs_foreach, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&robs_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&robs_contains, + /* .tp_getitem = */ NULL, + /* .tp_delitem = */ NULL, + /* .tp_setitem = */ NULL, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ &robs_nsi, + /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&robs_foreach, + /* .tp_foreach_pair = */ NULL, + /* .tp_bounditem = */ NULL, + /* .tp_hasitem = */ NULL, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&robs_size, + /* .tp_size_fast = */ NULL, + /* .tp_getitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&robs_getitem_index, + /* .tp_getitem_index_fast = */ NULL, + /* .tp_delitem_index = */ NULL, + /* .tp_setitem_index = */ NULL, + /* .tp_bounditem_index = */ NULL, + /* .tp_hasitem_index = */ NULL, + /* .tp_getrange_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t))&robs_getrange_index, + /* .tp_delrange_index = */ NULL, + /* .tp_setrange_index = */ NULL, + /* .tp_getrange_index_n = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t))&robs_getrange_index_n, + /* .tp_delrange_index_n = */ NULL, + /* .tp_setrange_index_n = */ NULL, + /* .tp_trygetitem = */ NULL, + /* .tp_trygetitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&robs_trygetitem_index, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; PRIVATE struct type_buffer robs_buffer = { @@ -2434,7 +2517,7 @@ INTERN DeeTypeObject RoBitset_Type = { /* .tp_repr = */ NULL, /* .tp_bool = */ (int (DCALL *)(DeeObject *__restrict))&robs_bool, /* .tp_print = */ NULL, - /* .tp_printrepr = */ (dssize_t (DCALL *)(DeeObject *__restrict, Dee_formatprinter_t, void *))&robs_printrepr, + /* .tp_printrepr = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_formatprinter_t, void *))&robs_printrepr, }, /* .tp_call = */ NULL, /* .tp_visit = */ NULL, @@ -2477,7 +2560,7 @@ bsv_err_readonly(BitsetView *__restrict self) { PRIVATE WUNUSED NONNULL((1)) size_t DCALL -bsv_nsi_getsize(BitsetView *__restrict self) { +bsv_size(BitsetView *__restrict self) { return bitset_npopcount(BitsetView_GetBitset(self), self->bsv_startbit, self->bsv_endbit); @@ -2678,11 +2761,6 @@ bsv_iter(BitsetView *__restrict self) { return NULL; } -PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -bsv_size(BitsetView *__restrict self) { - return DeeInt_NewSize(bsv_nsi_getsize(self)); -} - PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL bsv_contains(BitsetView *self, DeeObject *key) { size_t bitno; @@ -2695,11 +2773,27 @@ bsv_contains(BitsetView *self, DeeObject *key) { return NULL; } +PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL +bsv_getitem_index(BitsetView *self, size_t bitno) { + if unlikely(bitno >= BitsetView_GetNBits(self)) + goto err_too_large; + return_bool(bitset_test(BitsetView_GetBitset(self), + bitno + self->bsv_startbit)); +err_too_large: + bsv_err_bad_index(self, bitno); + return NULL; +} + +PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL +bsv_trygetitem_index(BitsetView *self, size_t bitno) { + if unlikely(bitno >= BitsetView_GetNBits(self)) + return ITER_DONE; + return_bool(bitset_test(BitsetView_GetBitset(self), + bitno + self->bsv_startbit)); +} + PRIVATE WUNUSED NONNULL((1)) int DCALL -bsv_delitem(BitsetView *self, DeeObject *key) { - size_t bitno; - if (DeeObject_AsSize(key, &bitno)) - goto err; +bsv_delitem_index(BitsetView *self, size_t bitno) { if unlikely(bitno >= BitsetView_GetNBits(self)) goto err_too_large; if unlikely(!BitsetView_IsWritable(self)) @@ -2710,16 +2804,11 @@ bsv_delitem(BitsetView *self, DeeObject *key) { return bsv_err_readonly(self); err_too_large: return bsv_err_bad_index(self, bitno); -err: - return -1; } PRIVATE WUNUSED NONNULL((1)) int DCALL -bsv_setitem(BitsetView *self, DeeObject *key, DeeObject *value) { +bsv_setitem_index(BitsetView *self, size_t bitno, DeeObject *value) { int temp; - size_t bitno; - if (DeeObject_AsSize(key, &bitno)) - goto err; if unlikely(bitno >= BitsetView_GetNBits(self)) goto err_too_large; if unlikely(!BitsetView_IsWritable(self)) @@ -2742,7 +2831,7 @@ bsv_setitem(BitsetView *self, DeeObject *key, DeeObject *value) { } PRIVATE WUNUSED NONNULL((1)) DREF BitsetView *DCALL -bsv_getrange_i(BitsetView *self, dssize_t start, dssize_t end) { +bsv_getrange_index(BitsetView *self, Dee_ssize_t start, Dee_ssize_t end) { struct Dee_seq_range range; DREF BitsetView *result; result = DeeObject_MALLOC(BitsetView); @@ -2768,56 +2857,64 @@ bsv_getrange_i(BitsetView *self, dssize_t start, dssize_t end) { } PRIVATE WUNUSED NONNULL((1)) DREF BitsetView *DCALL -bsv_getrange(BitsetView *self, DeeObject *start, DeeObject *end) { - Dee_ssize_t start_i, end_i = BitsetView_GetNBits(self); - if (DeeObject_AsSSize(start, &start_i)) +bsv_getrange_index_n(BitsetView *self, Dee_ssize_t start) { + DREF BitsetView *result; + result = DeeObject_MALLOC(BitsetView); + if unlikely(!result) goto err; - if (!DeeNone_Check(end)) { - if (DeeObject_AsSSize(end, &end_i)) - goto err; - } - return bsv_getrange_i(self, start_i, end_i); + result->bsv_owner = (DREF DeeObject *)self; + result->bsv_buf.bb_base = self->bsv_buf.bb_base; + result->bsv_buf.bb_size = self->bsv_buf.bb_size; +#ifndef __INTELLISENSE__ + result->bsv_buf.bb_put = self->bsv_buf.bb_put; + if (!result->bsv_buf.bb_put) + result->bsv_owner = self->bsv_owner; +#endif /* !__INTELLISENSE__ */ + Dee_Incref(result->bsv_owner); + result->bsv_startbit = DeeSeqRange_Clamp_n(start, BitsetView_GetNBits(self)) + self->bsv_startbit; + result->bsv_endbit = self->bsv_endbit; + result->bsv_bflags = self->bsv_bflags; + DeeObject_Init(result, &BitsetView_Type); + return result; err: return NULL; } PRIVATE WUNUSED NONNULL((1)) int DCALL -bsv_delrange(BitsetView *self, DeeObject *start, DeeObject *end) { +bsv_delrange_index(BitsetView *self, Dee_ssize_t start, Dee_ssize_t end) { struct Dee_seq_range range; - Dee_ssize_t start_i, end_i = BitsetView_GetNBits(self); - if (DeeObject_AsSSize(start, &start_i)) - goto err; - if (!DeeNone_Check(end)) { - if (DeeObject_AsSSize(end, &end_i)) - goto err; - } if unlikely(!BitsetView_IsWritable(self)) goto err_readonly; - DeeSeqRange_Clamp(&range, start_i, end_i, BitsetView_GetNBits(self)); + DeeSeqRange_Clamp(&range, start, end, BitsetView_GetNBits(self)); bitset_nclear(BitsetView_GetBitset(self), self->bsv_startbit + range.sr_start, self->bsv_startbit + range.sr_end); return 0; err_readonly: return bsv_err_readonly(self); -err: - return -1; } -PRIVATE WUNUSED NONNULL((1, 2, 3, 4)) int DCALL -bsv_setrange(BitsetView *self, DeeObject *start, - DeeObject *end, DeeObject *value) { - Dee_ssize_t start_i, end_i = BitsetView_GetNBits(self); +PRIVATE WUNUSED NONNULL((1)) int DCALL +bsv_delrange_index_n(BitsetView *self, Dee_ssize_t start) { + size_t used_start; + if unlikely(!BitsetView_IsWritable(self)) + goto err_readonly; + used_start = DeeSeqRange_Clamp_n(start, BitsetView_GetNBits(self)); + bitset_nclear(BitsetView_GetBitset(self), + self->bsv_startbit + used_start, + self->bsv_endbit); + return 0; +err_readonly: + return bsv_err_readonly(self); +} + +PRIVATE WUNUSED NONNULL((1, 4)) int DCALL +bsv_setrange_index(BitsetView *self, Dee_ssize_t start, + Dee_ssize_t end, DeeObject *value) { struct Dee_seq_range range; - if (DeeObject_AsSSize(start, &start_i)) - goto err; - if (!DeeNone_Check(end)) { - if (DeeObject_AsSSize(end, &end_i)) - goto err; - } if unlikely(!BitsetView_IsWritable(self)) goto err_readonly; - DeeSeqRange_Clamp(&range, start_i, end_i, BitsetView_GetNBits(self)); + DeeSeqRange_Clamp(&range, start, end, BitsetView_GetNBits(self)); if (DeeBool_Check(value)) { if (DeeBool_IsTrue(value)) { bitset_nset(BitsetView_GetBitset(self), @@ -2859,6 +2956,11 @@ bsv_setrange(BitsetView *self, DeeObject *start, return -1; } +PRIVATE WUNUSED NONNULL((1, 3)) int DCALL +bsv_setrange_index_n(BitsetView *self, Dee_ssize_t start, DeeObject *value) { + return bsv_setrange_index(self, start, SSIZE_MAX, value); +} + PRIVATE WUNUSED NONNULL((1, 2)) int DCALL bsv_getbuf(BitsetView *__restrict self, DeeBuffer *__restrict info, @@ -3429,22 +3531,22 @@ bsv_init(BitsetView *__restrict self, size_t argc, DeeObject *const *argv) { goto err_invalid_mode; } if (argc >= 3) { - if (DeeObject_AsSSize(argv[2], (dssize_t *)&start)) + if (DeeObject_AsSSize(argv[2], (Dee_ssize_t *)&start)) goto err; if (argc >= 4) { if unlikely(argc > 4) goto err_args; - if (DeeObject_AsSSize(argv[3], (dssize_t *)&end)) + if (DeeObject_AsSSize(argv[3], (Dee_ssize_t *)&end)) goto err; } } } else { - if (DeeObject_AsSSize(argv[1], (dssize_t *)&start)) + if (DeeObject_AsSSize(argv[1], (Dee_ssize_t *)&start)) goto err; if (argc >= 3) { if unlikely(argc > 3) goto err_args; - if (DeeObject_AsSSize(argv[2], (dssize_t *)&end)) + if (DeeObject_AsSSize(argv[2], (Dee_ssize_t *)&end)) goto err; } } @@ -3747,9 +3849,9 @@ bsv_bool(BitsetView *self) { return bitset_nanyset(BitsetView_GetBitset(self), self->bsv_startbit, self->bsv_endbit) ? 1 : 0; } -PRIVATE WUNUSED NONNULL((1)) dssize_t DCALL +PRIVATE WUNUSED NONNULL((1)) Dee_ssize_t DCALL bsv_printrepr(BitsetView *__restrict self, dformatprinter printer, void *arg) { - dssize_t temp, result; + Dee_ssize_t temp, result; DeeObject *owner = self->bsv_owner; result = DeeFormat_Printf(printer, arg, "BitsetView(%r", owner); if unlikely(result < 0) @@ -3776,7 +3878,7 @@ bsv_printrepr(BitsetView *__restrict self, dformatprinter printer, void *arg) { PRIVATE WUNUSED NONNULL((1, 2)) Dee_ssize_t DCALL bsv_foreach(BitsetView *self, Dee_foreach_t proc, void *arg) { - dssize_t temp, result = 0; + Dee_ssize_t temp, result = 0; size_t bitno; bitset_nforeach (bitno, BitsetView_GetBitset(self), self->bsv_startbit, self->bsv_endbit) { @@ -3802,7 +3904,7 @@ PRIVATE struct type_nsi tpconst bsv_nsi = { /* .nsi_flags = */ TYPE_SEQX_FMUTABLE | TYPE_SEQX_FRESIZABLE, { /* .nsi_setlike = */ { - /* .nsi_getsize = */ (dfunptr_t)&bsv_nsi_getsize, + /* .nsi_getsize = */ (dfunptr_t)&bsv_size, /* .nsi_insert = */ (dfunptr_t)&bsv_nsi_insert, /* .nsi_remove = */ (dfunptr_t)&bsv_nsi_remove, } @@ -3855,17 +3957,48 @@ PRIVATE struct type_cmp bsv_cmp = { }; PRIVATE struct type_seq bsv_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&bsv_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&bsv_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&bsv_contains, - /* .tp_getitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&bsv_contains, - /* .tp_delitem = */ (int (DCALL *)(DeeObject *, DeeObject *))&bsv_delitem, - /* .tp_setitem = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))&bsv_setitem, - /* .tp_getrange = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *, DeeObject *))&bsv_getrange, - /* .tp_delrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))&bsv_delrange, - /* .tp_setrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *, DeeObject *))&bsv_setrange, - /* .tp_nsi = */ &bsv_nsi, - /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&bsv_foreach, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&bsv_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&bsv_contains, + /* .tp_getitem = */ NULL, + /* .tp_delitem = */ NULL, + /* .tp_setitem = */ NULL, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ &bsv_nsi, + /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&bsv_foreach, + /* .tp_foreach_pair = */ NULL, + /* .tp_bounditem = */ NULL, + /* .tp_hasitem = */ NULL, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&bsv_size, + /* .tp_size_fast = */ NULL, + /* .tp_getitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&bsv_getitem_index, + /* .tp_getitem_index_fast = */ NULL, + /* .tp_delitem_index = */ (int (DCALL *)(DeeObject *, size_t))&bsv_delitem_index, + /* .tp_setitem_index = */ (int (DCALL *)(DeeObject *, size_t, DeeObject *))&bsv_setitem_index, + /* .tp_bounditem_index = */ NULL, + /* .tp_hasitem_index = */ NULL, + /* .tp_getrange_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t))&bsv_getrange_index, + /* .tp_delrange_index = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t))&bsv_delrange_index, + /* .tp_setrange_index = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t, DeeObject *))&bsv_setrange_index, + /* .tp_getrange_index_n = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t))&bsv_getrange_index_n, + /* .tp_delrange_index_n = */ (int (DCALL *)(DeeObject *, Dee_ssize_t))&bsv_delrange_index_n, + /* .tp_setrange_index_n = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, DeeObject *))&bsv_setrange_index_n, + /* .tp_trygetitem = */ NULL, + /* .tp_trygetitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&bsv_trygetitem_index, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; PRIVATE struct type_buffer bsv_buffer = { @@ -4181,7 +4314,7 @@ INTERN DeeTypeObject BitsetView_Type = { /* .tp_repr = */ NULL, /* .tp_bool = */ (int (DCALL *)(DeeObject *__restrict))&bsv_bool, /* .tp_print = */ NULL, - /* .tp_printrepr = */ (dssize_t (DCALL *)(DeeObject *__restrict, Dee_formatprinter_t, void *))&bsv_printrepr, + /* .tp_printrepr = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_formatprinter_t, void *))&bsv_printrepr, }, /* .tp_call = */ NULL, /* .tp_visit = */ (void (DCALL *)(DeeObject *__restrict, dvisit_t, void *))&bsv_visit, diff --git a/src/dex/collections/deque.c b/src/dex/collections/deque.c index 1ca872efb..852404f22 100644 --- a/src/dex/collections/deque.c +++ b/src/dex/collections/deque.c @@ -42,8 +42,7 @@ DECL_BEGIN INTERN WUNUSED NONNULL((1, 2)) bool DCALL -Deque_PushFront_unlocked(Deque *__restrict self, - DeeObject *__restrict item) { +Deque_PushFront_unlocked(Deque *self, DeeObject *item) { DequeBucket *new_bucket; ASSERT(self->d_head_idx < self->d_bucket_sz); ASSERT(self->d_head_use <= self->d_bucket_sz); @@ -91,8 +90,7 @@ Deque_PushFront_unlocked(Deque *__restrict self, } INTERN WUNUSED NONNULL((1, 2)) bool DCALL -Deque_PushBack_unlocked(Deque *__restrict self, - DeeObject *__restrict item) { +Deque_PushBack_unlocked(Deque *self, DeeObject *item) { DequeBucket *new_bucket; ASSERT(self->d_head_idx < self->d_bucket_sz); ASSERT(self->d_head_use <= self->d_bucket_sz); @@ -274,9 +272,9 @@ Deque_lrrot_unlocked(Deque *__restrict self, size_t num_objects) { temp = DequeIterator_ITEM(&iter); while (num_objects--) { DequeIterator_Next(&iter, self); - next = DequeIterator_ITEM(&iter); + next = DequeIterator_ITEM(&iter); DequeIterator_ITEM(&iter) = temp; - temp = next; + temp = next; } DEQUE_HEAD(self) = temp; ++self->d_version; @@ -435,10 +433,8 @@ Deque_PopBack(Deque *__restrict self) { } /* Insert/delete items at a given index. */ -INTERN int DCALL -Deque_Insert(Deque *__restrict self, - size_t index, - DeeObject *__restrict item) { +INTERN WUNUSED NONNULL((1, 3)) int DCALL +Deque_Insert(Deque *self, size_t index, DeeObject *item) { again: Deque_LockWrite(self); if (index > self->d_size) @@ -470,7 +466,7 @@ Deque_Erase(Deque *__restrict self, result = self->d_size - (size_t)index; if (result > num_items) result = num_items; - pop_objv = (DREF DeeObject **)Dee_TryMalloca(result * sizeof(DREF DeeObject *)); + pop_objv = (DREF DeeObject **)Dee_TryMallocac(result, sizeof(DREF DeeObject *)); if unlikely(!pop_objv) { Deque_LockEndWrite(self); if (Dee_CollectMemory(result * sizeof(DREF DeeObject *))) @@ -490,7 +486,7 @@ Deque_Erase(Deque *__restrict self, /* Drop references to popped objects. */ Dee_Decrefv(pop_objv, result); Dee_Freea(pop_objv); - return (dssize_t)result; + return (Dee_ssize_t)result; } @@ -513,7 +509,7 @@ Deque_Pop(Deque *__restrict self, size_t index) { } INTERN WUNUSED NONNULL((1)) DREF DeeObject *DCALL -Deque_Pops(Deque *__restrict self, dssize_t index) { +Deque_Pops(Deque *__restrict self, Dee_ssize_t index) { DREF DeeObject *result; Deque_LockWrite(self); if unlikely(index < 0) @@ -779,16 +775,15 @@ deq_fini(Deque *__restrict self) { #if __SIZEOF_INT__ != __SIZEOF_SIZE_T__ -PRIVATE dssize_t DCALL +PRIVATE NONNULL((1, 2)) Dee_ssize_t DCALL deque_push_back(void *self, DeeObject *__restrict ob) { - return (dssize_t)Deque_PushBack((Deque *)self, ob); + return (Dee_ssize_t)Deque_PushBack((Deque *)self, ob); } #endif /* __SIZEOF_INT__ != __SIZEOF_SIZE_T__ */ PRIVATE WUNUSED NONNULL((1)) int DCALL -deq_init(Deque *__restrict self, - size_t argc, DeeObject *const *argv) { +deq_init(Deque *__restrict self, size_t argc, DeeObject *const *argv) { DeeObject *init = Dee_EmptySeq; self->d_bucket_sz = DEQUE_BUCKET_DEFAULT_SIZE; if (DeeArg_Unpack(argc, argv, "|o" UNPuSIZ ":Deque", &init, &self->d_bucket_sz)) @@ -833,8 +828,7 @@ deq_init(Deque *__restrict self, PRIVATE WUNUSED NONNULL((1, 2)) int DCALL -deq_assign(Deque *__restrict self, - DeeObject *__restrict seq) { +deq_assign(Deque *self, DeeObject *seq) { Deque bTemp, bOld; weakref_support_init(&bTemp); if (DeeObject_InstanceOfExact(seq, &Deque_Type)) { @@ -898,7 +892,8 @@ deq_moveassign(Deque *__restrict self, return 0; } -PRIVATE WUNUSED NONNULL((1)) int DCALL deq_bool(Deque *__restrict self) { +PRIVATE WUNUSED NONNULL((1)) int DCALL +deq_bool(Deque *__restrict self) { return atomic_read(&self->d_size) != 0; } @@ -935,7 +930,7 @@ deq_clear(Deque *__restrict self) { deq_fini(&bData); } -PRIVATE void DCALL +PRIVATE NONNULL((1)) void DCALL deq_pclear(Deque *__restrict self, unsigned int gc_priority) { Deque_LockWrite(self); if (self->d_size) { @@ -993,11 +988,6 @@ deq_iter(Deque *__restrict self) { return result; } -PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -deq_size(Deque *__restrict self) { - return DeeInt_NewSize(atomic_read(&self->d_size)); -} - PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL deq_contains(Deque *self, DeeObject *item) { Deque_LockRead(self); @@ -1033,12 +1023,14 @@ deq_contains(Deque *self, DeeObject *item) { return NULL; } -PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL -deq_get(Deque *self, DeeObject *index_ob) { - size_t index; +PRIVATE WUNUSED NONNULL((1)) size_t DCALL +deq_size(Deque *__restrict self) { + return atomic_read(&self->d_size); +} + +PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL +deq_getitem_index(Deque *__restrict self, size_t index) { DREF DeeObject *result; - if (DeeObject_AsSize(index_ob, &index)) - goto err; Deque_LockRead(self); if (index >= self->d_size) { size_t deq_size = self->d_size; @@ -1055,74 +1047,36 @@ deq_get(Deque *self, DeeObject *index_ob) { return NULL; } -PRIVATE WUNUSED NONNULL((1, 2)) int DCALL -deq_del(Deque *__restrict self, DeeObject *__restrict index_ob) { - size_t index; +PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL +deq_trygetitem_index(Deque *__restrict self, size_t index) { DREF DeeObject *result; - if (DeeObject_AsSize(index_ob, &index)) - goto err; - result = Deque_Pop(self, index); - if unlikely(!result) - goto err; - Dee_Decref(result); - return 0; -err: - return -1; -} - -PRIVATE WUNUSED NONNULL((1, 2, 3)) int DCALL -deq_set(Deque *__restrict self, - DeeObject *__restrict index_ob, - DeeObject *__restrict value) { - size_t index; - DREF DeeObject *oldval; - if (DeeObject_AsSize(index_ob, &index)) - goto err; Deque_LockRead(self); - if (index >= self->d_size) { - size_t deq_size = self->d_size; - COMPILER_READ_BARRIER(); + if unlikely(index >= self->d_size) { Deque_LockEndRead(self); - err_index_out_of_bounds((DeeObject *)self, index, deq_size); - goto err; + return ITER_DONE; } - /* Exchange the stored item. */ - Dee_Incref(value); - oldval = DEQUE_ITEM(self, index); - DEQUE_ITEM(self, index) = value; + result = DEQUE_ITEM(self, index); + Dee_Incref(result); Deque_LockEndRead(self); - Dee_Decref(oldval); - return 0; -err: - return -1; -} - -PRIVATE WUNUSED NONNULL((1)) size_t DCALL -deq_nsi_size(Deque *__restrict self) { - return atomic_read(&self->d_size); + return result; } PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -deq_nsi_getitem(Deque *__restrict self, size_t index) { +deq_getitem_index_fast(Deque *__restrict self, size_t index) { DREF DeeObject *result; Deque_LockRead(self); - if (index >= self->d_size) { - size_t deq_size = self->d_size; - COMPILER_READ_BARRIER(); + if unlikely(index >= self->d_size) { Deque_LockEndRead(self); - err_index_out_of_bounds((DeeObject *)self, index, deq_size); - goto err; + return NULL; /* >> The sequence is resizable and `index >= CURRENT_SIZE' */ } result = DEQUE_ITEM(self, index); Dee_Incref(result); Deque_LockEndRead(self); return result; -err: - return NULL; } PRIVATE WUNUSED NONNULL((1)) int DCALL -deq_nsi_delitem(Deque *__restrict self, size_t index) { +deq_delitem_index(Deque *__restrict self, size_t index) { DREF DeeObject *result; result = Deque_Pop(self, index); if unlikely(!result) @@ -1133,10 +1087,8 @@ deq_nsi_delitem(Deque *__restrict self, size_t index) { return -1; } -PRIVATE int DCALL -deq_nsi_setitem(Deque *__restrict self, - size_t index, - DeeObject *__restrict value) { +PRIVATE WUNUSED NONNULL((1, 3)) int DCALL +deq_setitem_index(Deque *self, size_t index, DeeObject *value) { DREF DeeObject *oldval; Deque_LockRead(self); if (index >= self->d_size) { @@ -1157,10 +1109,8 @@ deq_nsi_setitem(Deque *__restrict self, return -1; } -PRIVATE WUNUSED DREF DeeObject *DCALL -deq_nsi_xchitem(Deque *__restrict self, - size_t index, - DeeObject *__restrict value) { +PRIVATE WUNUSED NONNULL((1, 3)) DREF DeeObject *DCALL +deq_nsi_xchitem(Deque *self, size_t index, DeeObject *value) { DREF DeeObject *oldval; Deque_LockRead(self); if (index >= self->d_size) { @@ -1208,11 +1158,11 @@ PRIVATE struct type_nsi tpconst deq_nsi = { /* .nsi_flags = */ TYPE_SEQX_FMUTABLE | TYPE_SEQX_FRESIZABLE, { /* .nsi_seqlike = */ { - /* .nsi_getsize = */ (dfunptr_t)&deq_nsi_size, - /* .nsi_getsize_fast = */ (dfunptr_t)&deq_nsi_size, - /* .nsi_getitem = */ (dfunptr_t)&deq_nsi_getitem, - /* .nsi_delitem = */ (dfunptr_t)&deq_nsi_delitem, - /* .nsi_setitem = */ (dfunptr_t)&deq_nsi_setitem, + /* .nsi_getsize = */ (dfunptr_t)&deq_size, + /* .nsi_getsize_fast = */ (dfunptr_t)&deq_size, + /* .nsi_getitem = */ (dfunptr_t)&deq_getitem_index, + /* .nsi_delitem = */ (dfunptr_t)&deq_delitem_index, + /* .nsi_setitem = */ (dfunptr_t)&deq_setitem_index, /* .nsi_getitem_fast = */ (dfunptr_t)NULL, /* .nsi_getrange = */ (dfunptr_t)NULL, /* .nsi_getrange_n = */ (dfunptr_t)NULL, @@ -1237,20 +1187,51 @@ PRIVATE struct type_nsi tpconst deq_nsi = { }; PRIVATE struct type_seq deq_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&deq_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&deq_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&deq_contains, - /* .tp_getitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&deq_get, - /* .tp_delitem = */ (int (DCALL *)(DeeObject *, DeeObject *))&deq_del, - /* .tp_setitem = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))&deq_set, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&deq_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&deq_contains, + /* .tp_getitem = */ NULL, + /* .tp_delitem = */ NULL, + /* .tp_setitem = */ NULL, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ &deq_nsi, + /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&deq_foreach, + /* .tp_foreach_pair = */ NULL, + /* .tp_bounditem = */ NULL, + /* .tp_hasitem = */ NULL, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&deq_size, + /* .tp_size_fast = */ (size_t (DCALL *)(DeeObject *__restrict))&deq_size, + /* .tp_getitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&deq_getitem_index, + /* .tp_getitem_index_fast = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&deq_getitem_index_fast, + /* .tp_delitem_index = */ (int (DCALL *)(DeeObject *, size_t))&deq_delitem_index, + /* .tp_setitem_index = */ (int (DCALL *)(DeeObject *, size_t, DeeObject *))&deq_setitem_index, + /* .tp_bounditem_index = */ NULL, + /* .tp_hasitem_index = */ NULL, /* XXX: range operators? (Also: Add a fallback delrange / setrange in `sequence' that calls * forward to member functions `insert(index:?Dint, ob)', * `erase(index:?Dint, count:?Dint = 1)') */ - /* .tp_getrange = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *, DeeObject *))NULL, - /* .tp_delrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))NULL, - /* .tp_setrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *, DeeObject *))NULL, - /* .tp_nsi = */ &deq_nsi, - /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&deq_foreach, + /* .tp_getrange_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t))NULL, + /* .tp_delrange_index = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t))NULL, + /* .tp_setrange_index = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t, DeeObject *))NULL, + /* .tp_getrange_index_n = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t))NULL, + /* .tp_delrange_index_n = */ (int (DCALL *)(DeeObject *, Dee_ssize_t))NULL, + /* .tp_setrange_index_n = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, DeeObject *))NULL, + /* .tp_trygetitem = */ NULL, + /* .tp_trygetitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&deq_trygetitem_index, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL @@ -1395,7 +1376,7 @@ deq_sizeof(Deque *self) { Deque_LockRead(self); ASSERT((self->d_head != NULL) == (self->d_tail != NULL)); if (self->d_head) { - size_t count = 1; + size_t count = 1; DequeBucket *iter = self->d_head; for (; iter != self->d_tail; iter = iter->db_next) ++count; @@ -1759,8 +1740,7 @@ deqiter_getindex_ob(DequeIteratorObject *__restrict self) { } PRIVATE WUNUSED NONNULL((1, 2)) int DCALL -deqiter_setindex_ob(DequeIteratorObject *__restrict self, - DeeObject *__restrict value) { +deqiter_setindex_ob(DequeIteratorObject *self, DeeObject *value) { size_t newindex = (size_t)-1; if (!DeeNone_Check(value) && DeeObject_AsSize(value, &newindex)) diff --git a/src/dex/collections/fixedlist.c b/src/dex/collections/fixedlist.c index fca614b5a..59ab2af4f 100644 --- a/src/dex/collections/fixedlist.c +++ b/src/dex/collections/fixedlist.c @@ -471,17 +471,12 @@ PRIVATE struct type_gc tpconst fl_gc = { PRIVATE WUNUSED NONNULL((1)) size_t DCALL -fl_nsi_size(FixedList *__restrict self) { - return self->fl_size; -} - -PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL fl_size(FixedList *__restrict self) { - return DeeInt_NewSize(self->fl_size); + return self->fl_size; } PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -fl_nsi_getitem(FixedList *__restrict self, size_t index) { +fl_getitem_index(FixedList *__restrict self, size_t index) { DREF DeeObject *result; if unlikely(index >= self->fl_size) { err_index_out_of_bounds((DeeObject *)self, index, self->fl_size); @@ -502,7 +497,7 @@ fl_nsi_getitem(FixedList *__restrict self, size_t index) { } PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -fl_nsi_getitem_fast(FixedList *__restrict self, size_t index) { +fl_getitem_index_fast(FixedList *__restrict self, size_t index) { DREF DeeObject *result; ASSERT(index < self->fl_size); FixedList_LockRead(self); @@ -512,8 +507,48 @@ fl_nsi_getitem_fast(FixedList *__restrict self, size_t index) { return result; } +PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL +fl_trygetitem_index(FixedList *__restrict self, size_t index) { + DREF DeeObject *result; + if unlikely(index >= self->fl_size) + goto nope; + FixedList_LockRead(self); + result = self->fl_elem[index]; + if unlikely(!result) { + FixedList_LockEndRead(self); + goto nope; + } + Dee_Incref(result); + FixedList_LockEndRead(self); + return result; +nope: + return ITER_DONE; +} + PRIVATE WUNUSED NONNULL((1)) int DCALL -fl_nsi_delitem(FixedList *__restrict self, size_t index) { +fl_bounditem_index(FixedList *__restrict self, size_t index) { + DREF DeeObject *result; + if unlikely(index >= self->fl_size) + return -2; + FixedList_LockRead(self); + result = self->fl_elem[index]; + if unlikely(!result) { + FixedList_LockEndRead(self); + return 0; + } + Dee_Incref(result); + FixedList_LockEndRead(self); + return 1; +} + +PRIVATE WUNUSED NONNULL((1)) int DCALL +fl_hasitem_index(FixedList *__restrict self, size_t index) { + return index < self->fl_size ? 1 : 0; +} + + +PRIVATE WUNUSED NONNULL((1)) int DCALL +fl_delitem_index(FixedList *__restrict self, size_t index) { DREF DeeObject *oldval; if unlikely(index >= self->fl_size) { err_index_out_of_bounds((DeeObject *)self, index, self->fl_size); @@ -529,9 +564,8 @@ fl_nsi_delitem(FixedList *__restrict self, size_t index) { return -1; } -PRIVATE int DCALL -fl_nsi_setitem(FixedList *__restrict self, size_t index, - DeeObject *__restrict value) { +PRIVATE WUNUSED NONNULL((1, 3)) int DCALL +fl_setitem_index(FixedList *self, size_t index, DeeObject *value) { DREF DeeObject *oldval; if unlikely(index >= self->fl_size) { err_index_out_of_bounds((DeeObject *)self, index, self->fl_size); @@ -548,9 +582,8 @@ fl_nsi_setitem(FixedList *__restrict self, size_t index, return -1; } -PRIVATE WUNUSED DREF DeeObject *DCALL -fl_nsi_xchitem(FixedList *__restrict self, size_t index, - DeeObject *__restrict value) { +PRIVATE WUNUSED NONNULL((1, 3)) DREF DeeObject *DCALL +fl_nsi_xchitem(FixedList *self, size_t index, DeeObject *value) { DREF DeeObject *result; if unlikely(index >= self->fl_size) { err_index_out_of_bounds((DeeObject *)self, index, self->fl_size); @@ -572,42 +605,7 @@ fl_nsi_xchitem(FixedList *__restrict self, size_t index, } PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL -fl_getitem(FixedList *self, - DeeObject *index_ob) { - size_t index; - if (DeeObject_AsSize(index_ob, &index)) - goto err; - return fl_nsi_getitem(self, index); -err: - return NULL; -} - -PRIVATE WUNUSED NONNULL((1, 2)) int DCALL -fl_delitem(FixedList *__restrict self, - DeeObject *__restrict index_ob) { - size_t index; - if (DeeObject_AsSize(index_ob, &index)) - goto err; - return fl_nsi_delitem(self, index); -err: - return -1; -} - -PRIVATE WUNUSED NONNULL((1, 2, 3)) int DCALL -fl_setitem(FixedList *__restrict self, - DeeObject *__restrict index_ob, - DeeObject *__restrict value) { - size_t index; - if (DeeObject_AsSize(index_ob, &index)) - goto err; - return fl_nsi_setitem(self, index, value); -err: - return -1; -} - -PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL -fl_contains(FixedList *self, - DeeObject *value) { +fl_contains(FixedList *self, DeeObject *value) { size_t i; for (i = 0; i < self->fl_size; ++i) { DREF DeeObject *elem; @@ -644,7 +642,7 @@ fl_iter(FixedList *__restrict self) { } PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -fl_nsi_getrange(FixedList *__restrict self, dssize_t i_begin, dssize_t i_end) { +fl_getrange_index(FixedList *__restrict self, Dee_ssize_t i_begin, Dee_ssize_t i_end) { DREF FixedList *result; struct Dee_seq_range range; size_t range_size; @@ -671,9 +669,9 @@ fl_nsi_getrange(FixedList *__restrict self, dssize_t i_begin, dssize_t i_end) { } PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -fl_nsi_getrange_n(FixedList *__restrict self, dssize_t i_begin) { +fl_getrange_index_n(FixedList *__restrict self, Dee_ssize_t i_begin) { #ifdef __OPTIMIZE_SIZE__ - return fl_nsi_getrange(self, i_begin, SSIZE_MAX); + return fl_getrange_index(self, i_begin, SSIZE_MAX); #else /* __OPTIMIZE_SIZE__ */ DREF FixedList *result; size_t start, range_size; @@ -701,7 +699,7 @@ fl_nsi_getrange_n(FixedList *__restrict self, dssize_t i_begin) { } PRIVATE WUNUSED NONNULL((1)) int DCALL -fl_nsi_delrange(FixedList *__restrict self, dssize_t i_begin, dssize_t i_end) { +fl_delrange_index(FixedList *__restrict self, Dee_ssize_t i_begin, Dee_ssize_t i_end) { struct Dee_seq_range range; size_t range_size; DeeSeqRange_Clamp(&range, i_begin, i_end, self->fl_size); @@ -730,9 +728,9 @@ fl_nsi_delrange(FixedList *__restrict self, dssize_t i_begin, dssize_t i_end) { } PRIVATE WUNUSED NONNULL((1)) int DCALL -fl_nsi_delrange_n(FixedList *__restrict self, dssize_t i_begin) { +fl_delrange_index_n(FixedList *__restrict self, Dee_ssize_t i_begin) { #ifdef __OPTIMIZE_SIZE__ - return fl_nsi_delrange(self, i_begin, SSIZE_MAX); + return fl_delrange_index(self, i_begin, SSIZE_MAX); #else /* __OPTIMIZE_SIZE__ */ size_t start, range_size; start = DeeSeqRange_Clamp_n(i_begin, self->fl_size); @@ -762,8 +760,8 @@ fl_nsi_delrange_n(FixedList *__restrict self, dssize_t i_begin) { } PRIVATE WUNUSED NONNULL((1, 4)) int DCALL -fl_nsi_setrange(FixedList *self, dssize_t i_begin, - dssize_t i_end, DeeObject *values) { +fl_setrange_index(FixedList *self, Dee_ssize_t i_begin, + Dee_ssize_t i_end, DeeObject *values) { struct Dee_seq_range range; size_t i, range_size; DREF DeeObject **values_buf; @@ -794,9 +792,9 @@ fl_nsi_setrange(FixedList *self, dssize_t i_begin, } PRIVATE WUNUSED NONNULL((1, 3)) int DCALL -fl_nsi_setrange_n(FixedList *self, dssize_t i_begin, DeeObject *values) { +fl_setrange_index_n(FixedList *self, Dee_ssize_t i_begin, DeeObject *values) { #ifdef __OPTIMIZE_SIZE__ - return fl_nsi_setrange(self, i_begin, SSIZE_MAX, values); + return fl_setrange_index(self, i_begin, SSIZE_MAX, values); #else /* __OPTIMIZE_SIZE__ */ size_t i, start, range_size; DREF DeeObject **values_buf; @@ -827,50 +825,6 @@ fl_nsi_setrange_n(FixedList *self, dssize_t i_begin, DeeObject *values) { #endif /* !__OPTIMIZE_SIZE__ */ } - -PRIVATE WUNUSED NONNULL((1, 2, 3)) DREF DeeObject *DCALL -fl_getrange(FixedList *self, DeeObject *begin, DeeObject *end) { - dssize_t i_begin, i_end; - if (DeeObject_AsSSize(begin, &i_begin)) - goto err; - if (DeeNone_Check(end)) - return fl_nsi_getrange_n(self, i_begin); - if (DeeObject_AsSSize(end, &i_end)) - goto err; - return fl_nsi_getrange(self, i_begin, i_end); -err: - return NULL; -} - -PRIVATE WUNUSED NONNULL((1, 2, 3)) int DCALL -fl_delrange(FixedList *self, DeeObject *begin, DeeObject *end) { - dssize_t i_begin, i_end; - if (DeeObject_AsSSize(begin, &i_begin)) - goto err; - if (DeeNone_Check(end)) - return fl_nsi_delrange_n(self, i_begin); - if (DeeObject_AsSSize(end, &i_end)) - goto err; - return fl_nsi_delrange(self, i_begin, i_end); -err: - return -1; -} - -PRIVATE WUNUSED NONNULL((1, 2, 3, 4)) int DCALL -fl_setrange(FixedList *self, DeeObject *begin, - DeeObject *end, DeeObject *values) { - dssize_t i_begin, i_end; - if (DeeObject_AsSSize(begin, &i_begin)) - goto err; - if (DeeNone_Check(end)) - return fl_nsi_setrange_n(self, i_begin, values); - if (DeeObject_AsSSize(end, &i_end)) - goto err; - return fl_nsi_setrange(self, i_begin, i_end, values); -err: - return -1; -} - PRIVATE WUNUSED NONNULL((1, 4)) size_t DCALL fl_nsi_find(FixedList *self, size_t start, size_t end, DeeObject *keyed_search_item, DeeObject *key) { @@ -927,7 +881,7 @@ fl_nsi_rfind(FixedList *self, size_t start, size_t end, } PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -fl_nsi_pop(FixedList *__restrict self, dssize_t index) { +fl_nsi_pop(FixedList *__restrict self, Dee_ssize_t index) { DREF DeeObject *result; if (index < 0) index += self->fl_size; @@ -1143,18 +1097,18 @@ PRIVATE struct type_nsi tpconst fl_nsi = { /* .nsi_flags = */ TYPE_SEQX_FMUTABLE, { /* .nsi_seqlike = */ { - /* .nsi_getsize = */ (dfunptr_t)&fl_nsi_size, - /* .nsi_getsize_fast = */ (dfunptr_t)&fl_nsi_size, - /* .nsi_getitem = */ (dfunptr_t)&fl_nsi_getitem, - /* .nsi_delitem = */ (dfunptr_t)&fl_nsi_delitem, - /* .nsi_setitem = */ (dfunptr_t)&fl_nsi_setitem, - /* .nsi_getitem_fast = */ (dfunptr_t)&fl_nsi_getitem_fast, - /* .nsi_getrange = */ (dfunptr_t)&fl_nsi_getrange, - /* .nsi_getrange_n = */ (dfunptr_t)&fl_nsi_getrange_n, - /* .nsi_delrange = */ (dfunptr_t)&fl_nsi_delrange, - /* .nsi_delrange_n = */ (dfunptr_t)&fl_nsi_delrange_n, - /* .nsi_setrange = */ (dfunptr_t)&fl_nsi_setrange, - /* .nsi_setrange_n = */ (dfunptr_t)&fl_nsi_setrange_n, + /* .nsi_getsize = */ (dfunptr_t)&fl_size, + /* .nsi_getsize_fast = */ (dfunptr_t)&fl_size, + /* .nsi_getitem = */ (dfunptr_t)&fl_getitem_index, + /* .nsi_delitem = */ (dfunptr_t)&fl_delitem_index, + /* .nsi_setitem = */ (dfunptr_t)&fl_setitem_index, + /* .nsi_getitem_fast = */ (dfunptr_t)&fl_getitem_index_fast, + /* .nsi_getrange = */ (dfunptr_t)&fl_getrange_index, + /* .nsi_getrange_n = */ (dfunptr_t)&fl_getrange_index_n, + /* .nsi_delrange = */ (dfunptr_t)&fl_delrange_index, + /* .nsi_delrange_n = */ (dfunptr_t)&fl_delrange_index_n, + /* .nsi_setrange = */ (dfunptr_t)&fl_setrange_index, + /* .nsi_setrange_n = */ (dfunptr_t)&fl_setrange_index_n, /* .nsi_find = */ (dfunptr_t)&fl_nsi_find, /* .nsi_rfind = */ (dfunptr_t)&fl_nsi_rfind, /* .nsi_xch = */ (dfunptr_t)&fl_nsi_xchitem, @@ -1172,17 +1126,48 @@ PRIVATE struct type_nsi tpconst fl_nsi = { }; PRIVATE struct type_seq fl_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&fl_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&fl_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&fl_contains, - /* .tp_getitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&fl_getitem, - /* .tp_delitem = */ (int (DCALL *)(DeeObject *, DeeObject *))&fl_delitem, - /* .tp_setitem = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))&fl_setitem, - /* .tp_getrange = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *, DeeObject *))&fl_getrange, - /* .tp_delrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))&fl_delrange, - /* .tp_setrange = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *, DeeObject *))&fl_setrange, - /* .tp_nsi = */ &fl_nsi, - /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&fl_foreach, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&fl_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&fl_contains, + /* .tp_getitem = */ NULL, + /* .tp_delitem = */ NULL, + /* .tp_setitem = */ NULL, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ &fl_nsi, + /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&fl_foreach, + /* .tp_foreach_pair = */ NULL, + /* .tp_bounditem = */ NULL, + /* .tp_hasitem = */ NULL, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&fl_size, + /* .tp_size_fast = */ (size_t (DCALL *)(DeeObject *__restrict))&fl_size, + /* .tp_getitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&fl_getitem_index, + /* .tp_getitem_index_fast = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&fl_getitem_index_fast, + /* .tp_delitem_index = */ (int (DCALL *)(DeeObject *, size_t))&fl_delitem_index, + /* .tp_setitem_index = */ (int (DCALL *)(DeeObject *, size_t, DeeObject *))&fl_setitem_index, + /* .tp_bounditem_index = */ (int (DCALL *)(DeeObject *, size_t))&fl_bounditem_index, + /* .tp_hasitem_index = */ (int (DCALL *)(DeeObject *, size_t))&fl_hasitem_index, + /* .tp_getrange_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t))&fl_getrange_index, + /* .tp_delrange_index = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t))&fl_delrange_index, + /* .tp_setrange_index = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, Dee_ssize_t, DeeObject *))&fl_setrange_index, + /* .tp_getrange_index_n = */ (DREF DeeObject *(DCALL *)(DeeObject *, Dee_ssize_t))&fl_getrange_index_n, + /* .tp_delrange_index_n = */ (int (DCALL *)(DeeObject *, Dee_ssize_t))&fl_delrange_index_n, + /* .tp_setrange_index_n = */ (int (DCALL *)(DeeObject *, Dee_ssize_t, DeeObject *))&fl_setrange_index_n, + /* .tp_trygetitem = */ NULL, + /* .tp_trygetitem_index = */ (DREF DeeObject *(DCALL *)(DeeObject *, size_t))&fl_trygetitem_index, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL diff --git a/src/dex/collections/rangemap.c b/src/dex/collections/rangemap.c index 839a3102e..cac960670 100644 --- a/src/dex/collections/rangemap.c +++ b/src/dex/collections/rangemap.c @@ -650,7 +650,8 @@ PRIVATE struct type_seq rangemap_seq = { /* .tp_getrange = */ NULL, /* .tp_delrange = */ NULL, /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &rangemap_nsi + /* .tp_nsi = */ &rangemap_nsi, + /* TODO: New operators */ }; PRIVATE struct type_method tpconst rangemap_methods[] = { @@ -1282,7 +1283,8 @@ PRIVATE struct type_seq proxy_keys_seq = { /* .tp_getrange = */ NULL, /* .tp_delrange = */ NULL, /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &proxy_keys_nsi + /* .tp_nsi = */ &proxy_keys_nsi, + /* TODO: New operators */ }; PRIVATE struct type_seq proxy_values_seq = { @@ -1295,7 +1297,8 @@ PRIVATE struct type_seq proxy_values_seq = { /* .tp_getrange = */ NULL, /* .tp_delrange = */ NULL, /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &proxy_nsi + /* .tp_nsi = */ &proxy_nsi, + /* TODO: New operators */ }; PRIVATE struct type_seq proxy_items_seq = { @@ -1308,7 +1311,8 @@ PRIVATE struct type_seq proxy_items_seq = { /* .tp_getrange = */ NULL, /* .tp_delrange = */ NULL, /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &proxy_nsi + /* .tp_nsi = */ &proxy_nsi, + /* TODO: New operators */ }; PRIVATE struct type_seq proxy_nodes_seq = { @@ -1321,7 +1325,8 @@ PRIVATE struct type_seq proxy_nodes_seq = { /* .tp_getrange = */ NULL, /* .tp_delrange = */ NULL, /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &proxy_nsi + /* .tp_nsi = */ &proxy_nsi, + /* TODO: New operators */ }; PRIVATE struct type_seq proxy_ranges_seq = { @@ -1334,7 +1339,8 @@ PRIVATE struct type_seq proxy_ranges_seq = { /* .tp_getrange = */ NULL, /* .tp_delrange = */ NULL, /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &proxy_nsi + /* .tp_nsi = */ &proxy_nsi, + /* TODO: New operators */ }; PRIVATE struct type_seq proxy_mapitems_seq = { @@ -1347,7 +1353,8 @@ PRIVATE struct type_seq proxy_mapitems_seq = { /* .tp_getrange = */ NULL, /* .tp_delrange = */ NULL, /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &proxy_mapitems_nsi + /* .tp_nsi = */ &proxy_mapitems_nsi, + /* TODO: New operators */ }; PRIVATE struct type_seq proxy_asmap_seq = { @@ -1361,6 +1368,7 @@ PRIVATE struct type_seq proxy_asmap_seq = { /* .tp_delrange = */ NULL, /* .tp_setrange = */ NULL, /* .tp_nsi = */ &proxy_asmap_nsi, + /* TODO: New operators */ }; PRIVATE WUNUSED NONNULL((1)) DREF RangeMapProxy *DCALL diff --git a/src/dex/collections/rbtree.c b/src/dex/collections/rbtree.c index 95a288606..134943e17 100644 --- a/src/dex/collections/rbtree.c +++ b/src/dex/collections/rbtree.c @@ -3537,6 +3537,7 @@ PRIVATE struct type_seq rbtree_seq = { /* .tp_nsi = */ &rbtree_nsi, /* .tp_foreach = */ NULL, /* .tp_foreach_pair = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_pair_t, void *))&rbtree_foreach, + /* TODO: New operators */ }; PRIVATE struct type_gc tpconst rbtree_gc = { diff --git a/src/dex/collections/udict.c b/src/dex/collections/udict.c index 20650da56..e4aa1bbf0 100644 --- a/src/dex/collections/udict.c +++ b/src/dex/collections/udict.c @@ -729,6 +729,47 @@ udict_contains(UDict *self, DeeObject *key) { } +PRIVATE WUNUSED NONNULL((1, 2)) int DCALL +udict_bounditem(UDict *self, DeeObject *key) { + dhash_t i, perturb; + dhash_t hash = UHASH(key); + UDict_LockRead(self); + perturb = i = hash & self->ud_mask; + for (;; UDict_HashNx(i, perturb)) { + struct udict_item *item; + item = &self->ud_elem[i & self->ud_mask]; + if (USAME(item->di_key, key)) { + UDict_LockEndRead(self); + return 1; /* Found the item. */ + } + if (!item->di_key) + break; + } + UDict_LockEndRead(self); + return -2; +} + +PRIVATE WUNUSED NONNULL((1, 2)) int DCALL +udict_hasitem(UDict *self, DeeObject *key) { + dhash_t i, perturb; + dhash_t hash = UHASH(key); + UDict_LockRead(self); + perturb = i = hash & self->ud_mask; + for (;; UDict_HashNx(i, perturb)) { + struct udict_item *item; + item = &self->ud_elem[i & self->ud_mask]; + if (USAME(item->di_key, key)) { + UDict_LockEndRead(self); + return 1; /* Found the item. */ + } + if (!item->di_key) + break; + } + UDict_LockEndRead(self); + return 0; +} + + PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL udict_getitem(UDict *self, DeeObject *key) { dhash_t i, perturb; @@ -754,6 +795,31 @@ udict_getitem(UDict *self, DeeObject *key) { return NULL; } +PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL +udict_trygetitem(UDict *self, DeeObject *key) { + dhash_t i, perturb; + dhash_t hash = UHASH(key); + UDict_LockRead(self); + perturb = i = hash & self->ud_mask; + for (;; UDict_HashNx(i, perturb)) { + struct udict_item *item; + item = &self->ud_elem[i & self->ud_mask]; + if (USAME(item->di_key, key)) { + /* Found the item. */ + DREF DeeObject *result; + result = item->di_value; + Dee_Incref(result); + UDict_LockEndRead(self); + return result; + } + if (!item->di_key) + break; + } + UDict_LockEndRead(self); + return ITER_DONE; +} + + PRIVATE WUNUSED NONNULL((1, 2, 3)) DREF DeeObject *DCALL UDict_GetItemDef(UDict *self, DeeObject *key, DeeObject *def) { dhash_t i, perturb; @@ -969,7 +1035,7 @@ udict_setitem_ex(UDict *self, PRIVATE WUNUSED NONNULL((1)) size_t DCALL -udict_nsi_getsize(UDict *__restrict self) { +udict_size(UDict *__restrict self) { return atomic_read(&self->ud_used); } @@ -1005,11 +1071,6 @@ udict_nsi_insertnew(UDict *self, DeeObject *key, return -1; } -PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -udict_size(UDict *__restrict self) { - return DeeInt_NewSize(atomic_read(&self->ud_used)); -} - PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL udict_iter(UDict *__restrict self) { DREF UDictIterator *result; @@ -1424,7 +1485,7 @@ PRIVATE struct type_nsi tpconst udict_nsi = { /* .nsi_flags = */ TYPE_SEQX_FMUTABLE | TYPE_SEQX_FRESIZABLE, { /* .nsi_maplike = */ { - /* .nsi_getsize = */ (dfunptr_t)&udict_nsi_getsize, + /* .nsi_getsize = */ (dfunptr_t)&udict_size, /* .nsi_nextkey = */ (dfunptr_t)&udictiterator_nextkey, /* .nsi_nextvalue = */ (dfunptr_t)&udictiterator_nextvalue, /* .nsi_getdefault = */ (dfunptr_t)&UDict_GetItemDef, @@ -1436,18 +1497,48 @@ PRIVATE struct type_nsi tpconst udict_nsi = { }; PRIVATE struct type_seq udict_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&udict_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&udict_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&udict_contains, - /* .tp_getitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&udict_getitem, - /* .tp_delitem = */ (int (DCALL *)(DeeObject *, DeeObject *))&udict_delitem, - /* .tp_setitem = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))&udict_setitem, - /* .tp_getrange = */ NULL, - /* .tp_delrange = */ NULL, - /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &udict_nsi, - /* .tp_foreach = */ NULL, - /* .tp_foreach_pair = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_pair_t, void *))&udict_foreach, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&udict_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&udict_contains, + /* .tp_getitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&udict_getitem, + /* .tp_delitem = */ (int (DCALL *)(DeeObject *, DeeObject *))&udict_delitem, + /* .tp_setitem = */ (int (DCALL *)(DeeObject *, DeeObject *, DeeObject *))&udict_setitem, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ &udict_nsi, + /* .tp_foreach = */ NULL, + /* .tp_foreach_pair = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_pair_t, void *))&udict_foreach, + /* .tp_bounditem = */ (int (DCALL *)(DeeObject *, DeeObject *))&udict_bounditem, + /* .tp_hasitem = */ (int (DCALL *)(DeeObject *, DeeObject *))&udict_hasitem, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&udict_size, + /* .tp_size_fast = */ (size_t (DCALL *)(DeeObject *__restrict))&udict_size, + /* .tp_getitem_index = */ NULL, + /* .tp_getitem_index_fast = */ NULL, + /* .tp_delitem_index = */ NULL, + /* .tp_setitem_index = */ NULL, + /* .tp_bounditem_index = */ NULL, + /* .tp_hasitem_index = */ NULL, + /* .tp_getrange_index = */ NULL, + /* .tp_delrange_index = */ NULL, + /* .tp_setrange_index = */ NULL, + /* .tp_getrange_index_n = */ NULL, + /* .tp_delrange_index_n = */ NULL, + /* .tp_setrange_index_n = */ NULL, + /* .tp_trygetitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&udict_trygetitem, + /* .tp_trygetitem_index = */ NULL, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; @@ -1970,7 +2061,7 @@ urodict_printrepr(URoDict *__restrict self, } PRIVATE WUNUSED NONNULL((1)) size_t DCALL -urodict_nsi_getsize(URoDict *__restrict self) { +urodict_size(URoDict *__restrict self) { ASSERT(self->urd_size != (size_t)-2); return self->urd_size; } @@ -2009,11 +2100,6 @@ urodict_iter(URoDict *__restrict self) { return result; } -PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -urodict_size(URoDict *__restrict self) { - return DeeInt_NewSize(self->urd_size); -} - PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL urodict_contains(URoDict *self, DeeObject *key) { size_t i, perturb, hash; @@ -2047,6 +2133,54 @@ urodict_getitem(URoDict *self, DeeObject *key) { return NULL; } +PRIVATE WUNUSED NONNULL((1, 2)) int DCALL +urodict_bounditem(URoDict *self, DeeObject *key) { + size_t i, perturb, hash; + struct udict_item *item; + hash = UHASH(key); + perturb = i = hash & self->urd_mask; + for (;; URoDict_HashNx(i, perturb)) { + item = &self->urd_elem[i & self->urd_mask]; + if (!item->di_key) + break; + if (USAME(item->di_key, key)) + return 1; /* Found it! */ + } + return -2; +} + +PRIVATE WUNUSED NONNULL((1, 2)) int DCALL +urodict_hasitem(URoDict *self, DeeObject *key) { + size_t i, perturb, hash; + struct udict_item *item; + hash = UHASH(key); + perturb = i = hash & self->urd_mask; + for (;; URoDict_HashNx(i, perturb)) { + item = &self->urd_elem[i & self->urd_mask]; + if (!item->di_key) + break; + if (USAME(item->di_key, key)) + return 1; /* Found it! */ + } + return 0; +} + +PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL +urodict_trygetitem(URoDict *self, DeeObject *key) { + size_t i, perturb, hash; + struct udict_item *item; + hash = UHASH(key); + perturb = i = hash & self->urd_mask; + for (;; URoDict_HashNx(i, perturb)) { + item = &self->urd_elem[i & self->urd_mask]; + if (!item->di_key) + break; + if (USAME(item->di_key, key)) + return_reference_(item->di_value); /* Found it! */ + } + return ITER_DONE; +} + PRIVATE WUNUSED NONNULL((1, 2)) Dee_ssize_t DCALL urodict_foreach(URoDict *self, Dee_foreach_pair_t proc, void *arg) { Dee_ssize_t temp, result = 0; @@ -2071,7 +2205,7 @@ PRIVATE struct type_nsi tpconst urodict_nsi = { /* .nsi_flags = */ TYPE_SEQX_FNORMAL, { /* .nsi_maplike = */ { - /* .nsi_getsize = */ (dfunptr_t)&urodict_nsi_getsize, + /* .nsi_getsize = */ (dfunptr_t)&urodict_size, /* .nsi_nextkey = */ (dfunptr_t)&urodictiterator_nextkey, /* .nsi_nextvalue = */ (dfunptr_t)&urodictiterator_nextvalue, /* .nsi_getdefault = */ (dfunptr_t)&URoDict_GetItemDef @@ -2081,18 +2215,48 @@ PRIVATE struct type_nsi tpconst urodict_nsi = { PRIVATE struct type_seq urodict_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&urodict_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&urodict_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&urodict_contains, - /* .tp_getitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&urodict_getitem, - /* .tp_delitem = */ NULL, - /* .tp_setitem = */ NULL, - /* .tp_getrange = */ NULL, - /* .tp_delrange = */ NULL, - /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &urodict_nsi, - /* .tp_foreach = */ NULL, - /* .tp_foreach_pair = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_pair_t, void *))&urodict_foreach, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&urodict_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&urodict_contains, + /* .tp_getitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&urodict_getitem, + /* .tp_delitem = */ NULL, + /* .tp_setitem = */ NULL, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ &urodict_nsi, + /* .tp_foreach = */ NULL, + /* .tp_foreach_pair = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_pair_t, void *))&urodict_foreach, + /* .tp_bounditem = */ (int (DCALL *)(DeeObject *, DeeObject *))&urodict_bounditem, + /* .tp_hasitem = */ (int (DCALL *)(DeeObject *, DeeObject *))&urodict_hasitem, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&urodict_size, + /* .tp_size_fast = */ (size_t (DCALL *)(DeeObject *__restrict))&urodict_size, + /* .tp_getitem_index = */ NULL, + /* .tp_getitem_index_fast = */ NULL, + /* .tp_delitem_index = */ NULL, + /* .tp_setitem_index = */ NULL, + /* .tp_bounditem_index = */ NULL, + /* .tp_hasitem_index = */ NULL, + /* .tp_getrange_index = */ NULL, + /* .tp_delrange_index = */ NULL, + /* .tp_setrange_index = */ NULL, + /* .tp_getrange_index_n = */ NULL, + /* .tp_delrange_index_n = */ NULL, + /* .tp_setrange_index_n = */ NULL, + /* .tp_trygetitem = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&urodict_trygetitem, + /* .tp_trygetitem_index = */ NULL, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL diff --git a/src/dex/collections/uset.c b/src/dex/collections/uset.c index f29c4717c..5c74d8466 100644 --- a/src/dex/collections/uset.c +++ b/src/dex/collections/uset.c @@ -963,13 +963,8 @@ uset_iter(USet *__restrict self) { } -PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL -uset_size(USet *__restrict self) { - return DeeInt_NewSize(atomic_read(&self->us_used)); -} - PRIVATE WUNUSED NONNULL((1)) size_t DCALL -uset_nsi_getsize(USet *__restrict self) { +uset_size(USet *__restrict self) { return atomic_read(&self->us_used); } @@ -1240,7 +1235,7 @@ PRIVATE struct type_nsi tpconst uset_nsi = { /* .nsi_flags = */ TYPE_SEQX_FMUTABLE | TYPE_SEQX_FRESIZABLE, { /* .nsi_setlike = */ { - /* .nsi_getsize = */ (dfunptr_t)&uset_nsi_getsize, + /* .nsi_getsize = */ (dfunptr_t)&uset_size, /* .nsi_insert = */ (dfunptr_t)&USet_Insert, /* .nsi_remove = */ (dfunptr_t)&USet_Remove, } @@ -1248,17 +1243,48 @@ PRIVATE struct type_nsi tpconst uset_nsi = { }; PRIVATE struct type_seq uset_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&uset_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&uset_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&uset_contains, - /* .tp_getitem = */ NULL, - /* .tp_delitem = */ NULL, - /* .tp_setitem = */ NULL, - /* .tp_getrange = */ NULL, - /* .tp_delrange = */ NULL, - /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &uset_nsi, - /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&uset_foreach, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&uset_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&uset_contains, + /* .tp_getitem = */ NULL, + /* .tp_delitem = */ NULL, + /* .tp_setitem = */ NULL, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ &uset_nsi, + /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&uset_foreach, + /* .tp_foreach_pair = */ NULL, + /* .tp_bounditem = */ NULL, + /* .tp_hasitem = */ NULL, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&uset_size, + /* .tp_size_fast = */ (size_t (DCALL *)(DeeObject *__restrict))&uset_size, + /* .tp_getitem_index = */ NULL, + /* .tp_getitem_index_fast = */ NULL, + /* .tp_delitem_index = */ NULL, + /* .tp_setitem_index = */ NULL, + /* .tp_bounditem_index = */ NULL, + /* .tp_hasitem_index = */ NULL, + /* .tp_getrange_index = */ NULL, + /* .tp_delrange_index = */ NULL, + /* .tp_setrange_index = */ NULL, + /* .tp_getrange_index_n = */ NULL, + /* .tp_delrange_index_n = */ NULL, + /* .tp_setrange_index_n = */ NULL, + /* .tp_trygetitem = */ NULL, + /* .tp_trygetitem_index = */ NULL, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; PRIVATE struct type_method tpconst uset_methods[] = { @@ -1518,9 +1544,8 @@ INTERN DeeTypeObject URoSetIterator_Type = { STATIC_ASSERT(offsetof(URoSet, urs_size) == offsetof(USet, us_used)); -#define uroset_size uset_size -#define uroset_bool uset_bool -#define uroset_nsi_getsize uset_nsi_getsize +#define uroset_size uset_size +#define uroset_bool uset_bool PRIVATE WUNUSED NONNULL((1, 2)) dssize_t DCALL @@ -1553,7 +1578,7 @@ PRIVATE struct type_nsi tpconst uroset_nsi = { /* .nsi_flags = */ TYPE_SEQX_FNORMAL, { /* .nsi_setlike = */ { - /* .nsi_getsize = */ (dfunptr_t)&uroset_nsi_getsize, + /* .nsi_getsize = */ (dfunptr_t)&uroset_size, } } }; @@ -1615,17 +1640,48 @@ uroset_foreach(URoSet *self, Dee_foreach_t proc, void *arg) { } PRIVATE struct type_seq uroset_seq = { - /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&uroset_iter, - /* .tp_sizeob = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&uroset_size, - /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&uroset_contains, - /* .tp_getitem = */ NULL, - /* .tp_delitem = */ NULL, - /* .tp_setitem = */ NULL, - /* .tp_getrange = */ NULL, - /* .tp_delrange = */ NULL, - /* .tp_setrange = */ NULL, - /* .tp_nsi = */ &uroset_nsi, - /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&uroset_foreach, + /* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&uroset_iter, + /* .tp_sizeob = */ NULL, + /* .tp_contains = */ (DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&uroset_contains, + /* .tp_getitem = */ NULL, + /* .tp_delitem = */ NULL, + /* .tp_setitem = */ NULL, + /* .tp_getrange = */ NULL, + /* .tp_delrange = */ NULL, + /* .tp_setrange = */ NULL, + /* .tp_nsi = */ &uroset_nsi, + /* .tp_foreach = */ (Dee_ssize_t (DCALL *)(DeeObject *__restrict, Dee_foreach_t, void *))&uroset_foreach, + /* .tp_foreach_pair = */ NULL, + /* .tp_bounditem = */ NULL, + /* .tp_hasitem = */ NULL, + /* .tp_size = */ (size_t (DCALL *)(DeeObject *__restrict))&uroset_size, + /* .tp_size_fast = */ (size_t (DCALL *)(DeeObject *__restrict))&uroset_size, + /* .tp_getitem_index = */ NULL, + /* .tp_getitem_index_fast = */ NULL, + /* .tp_delitem_index = */ NULL, + /* .tp_setitem_index = */ NULL, + /* .tp_bounditem_index = */ NULL, + /* .tp_hasitem_index = */ NULL, + /* .tp_getrange_index = */ NULL, + /* .tp_delrange_index = */ NULL, + /* .tp_setrange_index = */ NULL, + /* .tp_getrange_index_n = */ NULL, + /* .tp_delrange_index_n = */ NULL, + /* .tp_setrange_index_n = */ NULL, + /* .tp_trygetitem = */ NULL, + /* .tp_trygetitem_index = */ NULL, + /* .tp_trygetitem_string_hash = */ NULL, + /* .tp_getitem_string_hash = */ NULL, + /* .tp_delitem_string_hash = */ NULL, + /* .tp_setitem_string_hash = */ NULL, + /* .tp_bounditem_string_hash = */ NULL, + /* .tp_hasitem_string_hash = */ NULL, + /* .tp_trygetitem_string_len_hash = */ NULL, + /* .tp_getitem_string_len_hash = */ NULL, + /* .tp_delitem_string_len_hash = */ NULL, + /* .tp_setitem_string_len_hash = */ NULL, + /* .tp_bounditem_string_len_hash = */ NULL, + /* .tp_hasitem_string_len_hash = */ NULL, }; PRIVATE NONNULL((1, 2)) void DCALL