mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-12 02:13:04 +08:00
Overwrite present number keys in the lookup that checks for growth (#1056)
This commit is contained in:
@@ -1003,10 +1003,19 @@ static inline bool scr_map_append_grows_index(const ScrMap *m) {
|
||||
|
||||
/* Number keys arrive normalized (+0 for -0, canonical NaN). A directly
|
||||
* indexed map overwrites or appends through its table; a key the table
|
||||
* cannot hold converts it to hashing first. */
|
||||
* cannot hold converts it to hashing first. When an append would grow a
|
||||
* hashed map's index, the lookup that decides whether the key is new also
|
||||
* overwrites a key that is already present. */
|
||||
static void scr_map_set_f64_slot(ScrMap *m, uint64_t key, uint64_t val) {
|
||||
double k = scr_map_slot_to_f64(key);
|
||||
if (!m->ndense && scr_map_append_grows_index(m) && scr_map_find_f64(m, k) == SCR_MAP_EMPTY) {
|
||||
if (!m->ndense && scr_map_append_grows_index(m)) {
|
||||
size_t e = scr_map_find_f64(m, k);
|
||||
if (e != SCR_MAP_EMPTY) {
|
||||
uint64_t old = m->entries[e].val;
|
||||
m->entries[e].val = val; /* unlink before releasing (cycle collector) */
|
||||
scr_map_release_val(m, old);
|
||||
return;
|
||||
}
|
||||
scr_map_enter_dense(m, k); /* the append would grow the index */
|
||||
}
|
||||
if (m->ndense) {
|
||||
|
||||
Reference in New Issue
Block a user