Skip to content

Commit

Permalink
Add support for tp_asvector to types from collections
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Jun 2, 2024
1 parent df121ad commit 14bfea6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/dex/collections/uset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,26 @@ uset_foreach(USet *self, Dee_foreach_t proc, void *arg) {
return temp;
}

PRIVATE WUNUSED NONNULL((1)) size_t DCALL
uset_asvector(USet *self, /*out*/ DREF DeeObject **dst, size_t dst_length) {
size_t result;
USet_LockRead(self);
result = self->us_used;
if likely(dst_length >= result) {
struct uset_item *iter, *end;
end = (iter = self->us_elem) + (self->us_mask + 1);
for (; iter < end; ++iter) {
DeeObject *key = iter->usi_key;
if (key == NULL || key == dummy)
continue;
Dee_Incref(key);
*dst++ = key;
}
}
USet_LockEndRead(self);
return result;
}


PRIVATE struct type_nsi tpconst uset_nsi = {
/* .nsi_class = */ TYPE_SEQX_CLASS_SET,
Expand Down Expand Up @@ -1280,6 +1300,7 @@ PRIVATE struct type_seq uset_seq = {
/* .tp_setitem_string_len_hash = */ NULL,
/* .tp_bounditem_string_len_hash = */ NULL,
/* .tp_hasitem_string_len_hash = */ NULL,
/* .tp_asvector = */ (size_t (DCALL *)(DeeObject *, DREF DeeObject **, size_t))&uset_asvector,
};

PRIVATE struct type_method tpconst uset_methods[] = {
Expand Down Expand Up @@ -1634,6 +1655,23 @@ uroset_foreach(URoSet *self, Dee_foreach_t proc, void *arg) {
return temp;
}

PRIVATE WUNUSED NONNULL((1)) size_t DCALL
uroset_asvector(URoSet *self, /*out*/ DREF DeeObject **dst, size_t dst_length) {
if likely(dst_length >= self->urs_size) {
struct uset_item *iter, *end;
end = (iter = self->urs_elem) + (self->urs_mask + 1);
for (; iter < end; ++iter) {
DeeObject *key = iter->usi_key;
if (key == NULL)
continue;
Dee_Incref(key);
*dst++ = key;
}
}
return self->urs_size;
}


PRIVATE struct type_seq uroset_seq = {
/* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&uroset_iter,
/* .tp_sizeob = */ NULL,
Expand Down Expand Up @@ -1680,6 +1718,7 @@ PRIVATE struct type_seq uroset_seq = {
/* .tp_setitem_string_len_hash = */ NULL,
/* .tp_bounditem_string_len_hash = */ NULL,
/* .tp_hasitem_string_len_hash = */ NULL,
/* .tp_asvector = */ (size_t (DCALL *)(DeeObject *, DREF DeeObject **, size_t))&uroset_asvector,
};

PRIVATE NONNULL((1, 2)) void DCALL
Expand Down

0 comments on commit 14bfea6

Please sign in to comment.