Ignore:
Timestamp:
2023-02-05T22:03:19Z (15 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b596d0d
Parents:
07700ed
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-05 22:01:46)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-05 22:03:19)
Message:

Make hash table operations immutable, because global mutable state is evil

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/adt/hash_table.c

    r07700ed r61eb2ce2  
    9191 */
    9292bool hash_table_create(hash_table_t *h, size_t init_size, size_t max_load,
    93     hash_table_ops_t *op)
     93    const hash_table_ops_t *op)
    9494{
    9595        assert(h);
     
    111111        h->apply_ongoing = false;
    112112
    113         if (h->op->remove_callback == NULL) {
    114                 h->op->remove_callback = nop_remove_callback;
    115         }
    116 
    117113        return true;
    118114}
     
    172168        if (h->item_cnt == 0)
    173169                return;
     170
     171        void (*remove_cb)(ht_link_t *) = h->op->remove_callback ? h->op->remove_callback : nop_remove_callback;
    174172
    175173        for (size_t idx = 0; idx < h->bucket_cnt; ++idx) {
     
    179177
    180178                        list_remove(cur);
    181                         h->op->remove_callback(cur_link);
     179                        remove_cb(cur_link);
    182180                }
    183181        }
     
    322320                        ++removed;
    323321                        list_remove(cur);
    324                         h->op->remove_callback(cur_link);
     322
     323                        if (h->op->remove_callback)
     324                                h->op->remove_callback(cur_link);
    325325                }
    326326        }
     
    341341        list_remove(&item->link);
    342342        --h->item_cnt;
    343         h->op->remove_callback(item);
     343
     344        if (h->op->remove_callback)
     345                h->op->remove_callback(item);
    344346        shrink_if_needed(h);
    345347}
Note: See TracChangeset for help on using the changeset viewer.