mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
better dict clear
This commit is contained in:
parent
a8ca70ca74
commit
7549f1b95a
@ -8,6 +8,7 @@ extern "C" {
|
|||||||
#include "pocketpy/objects/pyvar.h"
|
#include "pocketpy/objects/pyvar.h"
|
||||||
#include "pocketpy/common/vector.h"
|
#include "pocketpy/common/vector.h"
|
||||||
|
|
||||||
|
/** @brief `pkpy_Dict` is the Dict type in Python */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int count; /** number of elements in the dictionary */
|
int count; /** number of elements in the dictionary */
|
||||||
c11_vector _entries; /** contains `pkpy_DictEntry` (hidden type) */
|
c11_vector _entries; /** contains `pkpy_DictEntry` (hidden type) */
|
||||||
@ -15,9 +16,9 @@ typedef struct {
|
|||||||
void* _hashtable; /** contains indecies, can be `u8`, `u16` or `u32` according to size*/
|
void* _hashtable; /** contains indecies, can be `u8`, `u16` or `u32` according to size*/
|
||||||
} pkpy_Dict;
|
} pkpy_Dict;
|
||||||
|
|
||||||
|
/** @brief `pkpy_DictIter` is used to iterate over a `pkpy_Dict` */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const pkpy_Dict* _dict;
|
const pkpy_Dict* _dict;
|
||||||
unsigned int _version;
|
|
||||||
int _index;
|
int _index;
|
||||||
} pkpy_DictIter;
|
} pkpy_DictIter;
|
||||||
|
|
||||||
|
@ -227,8 +227,15 @@ void pkpy_Dict__update(pkpy_Dict *self, void *vm, const pkpy_Dict *other) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pkpy_Dict__clear(pkpy_Dict *self) {
|
void pkpy_Dict__clear(pkpy_Dict *self) {
|
||||||
pkpy_Dict__dtor(self);
|
self->count = 0;
|
||||||
pkpy_Dict__ctor(self);
|
c11_vector__dtor(&self->_entries);
|
||||||
|
c11_vector__ctor(&self->_entries, sizeof(struct pkpy_DictEntry));
|
||||||
|
if (self->_hashtable > 16) {
|
||||||
|
free(self->_hashtable);
|
||||||
|
self->_htcap = 16;
|
||||||
|
self->_hashtable = malloc(pkpy_Dict__ht_byte_size(self));
|
||||||
|
}
|
||||||
|
memset(self->_hashtable, 0xff, pkpy_Dict__ht_byte_size(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pkpy_Dict__next_entry_idx(const pkpy_Dict* self, int idx) {
|
static int pkpy_Dict__next_entry_idx(const pkpy_Dict* self, int idx) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user