Skip to content

Commit e5dbe1e

Browse files
pfalcondpgeorge
authored andcommitted
map: Add empty fixed map.
Useful when need to call kw-receiving functions without any keywords from C, etc.
1 parent 317cf18 commit e5dbe1e

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

py/map.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
#include "obj.h"
3535
#include "runtime0.h"
3636

37+
// Fixed empty map. Useful when need to call kw-receiving functions
38+
// without any keywords from C, etc.
39+
const mp_map_t mp_const_empty_map = {
40+
.all_keys_are_qstrs = 0,
41+
.table_is_fixed_array = 1,
42+
.used = 0,
43+
.alloc = 0,
44+
.table = NULL,
45+
};
46+
3747
// approximatelly doubling primes; made with Mathematica command: Table[Prime[Floor[(1.7)^n]], {n, 3, 24}]
3848
// prefixed with zero for the empty case.
3949
STATIC uint32_t doubling_primes[] = {0, 7, 19, 43, 89, 179, 347, 647, 1229, 2297, 4243, 7829, 14347, 26017, 47149, 84947, 152443, 273253, 488399, 869927, 1547173, 2745121, 4861607};

py/obj.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ typedef enum _mp_map_lookup_kind_t {
148148
MP_MAP_LOOKUP_REMOVE_IF_FOUND, // 2
149149
} mp_map_lookup_kind_t;
150150

151+
extern const mp_map_t mp_const_empty_map;
152+
151153
static inline bool MP_MAP_SLOT_IS_FILLED(const mp_map_t *map, mp_uint_t pos) { return ((map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL); }
152154

153155
void mp_map_init(mp_map_t *map, mp_uint_t n);

0 commit comments

Comments
 (0)