diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index 49ca4ae7..2225b7d8 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -584,28 +584,19 @@ static nghttp2_hd_entry *hd_map_find(nghttp2_hd_map *map, int *exact_match, } static void hd_map_remove(nghttp2_hd_map *map, nghttp2_hd_entry *ent) { - nghttp2_hd_entry **bucket; - nghttp2_hd_entry *p; + nghttp2_hd_entry **dst; - bucket = &map->table[ent->hash & (HD_MAP_SIZE - 1)]; + dst = &map->table[ent->hash & (HD_MAP_SIZE - 1)]; - if (*bucket == NULL) { - return; - } + for (; *dst; dst = &(*dst)->next) { + if (*dst != ent) { + continue; + } - if (*bucket == ent) { - *bucket = ent->next; + *dst = ent->next; ent->next = NULL; return; } - - for (p = *bucket; p; p = p->next) { - if (p->next == ent) { - p->next = ent->next; - ent->next = NULL; - return; - } - } } static int hd_ringbuf_init(nghttp2_hd_ringbuf *ringbuf, size_t bufsize, diff --git a/lib/nghttp2_map.c b/lib/nghttp2_map.c index 63585571..4d9f97b4 100644 --- a/lib/nghttp2_map.c +++ b/lib/nghttp2_map.c @@ -170,20 +170,18 @@ nghttp2_map_entry *nghttp2_map_find(nghttp2_map *map, key_type key) { int nghttp2_map_remove(nghttp2_map *map, key_type key) { uint32_t h; - nghttp2_map_entry *entry, *prev; + nghttp2_map_entry **dst; + h = hash(key, map->tablelen); - prev = NULL; - for (entry = map->table[h]; entry; entry = entry->next) { - if (entry->key == key) { - if (prev == NULL) { - map->table[h] = entry->next; - } else { - prev->next = entry->next; - } - --map->size; - return 0; + + for (dst = &map->table[h]; *dst; dst = &(*dst)->next) { + if ((*dst)->key != key) { + continue; } - prev = entry; + + *dst = (*dst)->next; + --map->size; + return 0; } return NGHTTP2_ERR_INVALID_ARGUMENT; }