Commit b48ceac5 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttp2_hd: Search dynamic table first

Since recently used headers are in dynamic header table, it is
advantageous to search dynamic table first, saving time to search
through static table.
parent 34413d8d
......@@ -842,6 +842,27 @@ static search_result search_hd_table(nghttp2_hd_context *context,
size_t i;
int use_index = (nv->flags & NGHTTP2_NV_FLAG_NO_INDEX) == 0;
/* Search dynamic table first, so that we can find recently used
entry first */
if(use_index) {
for(i = 0; i < context->hd_table.len; ++i) {
nghttp2_hd_entry *ent = hd_ringbuf_get(&context->hd_table, i);
if(ent->name_hash != name_hash || !name_eq(&ent->nv, nv)) {
continue;
}
if(res.index == -1) {
res.index = (ssize_t)(i + NGHTTP2_STATIC_TABLE_LENGTH);
}
if(ent->value_hash == value_hash && value_eq(&ent->nv, nv)) {
res.index = (ssize_t)(i + NGHTTP2_STATIC_TABLE_LENGTH);
res.name_value_match = 1;
return res;
}
}
}
for(i = 0; i < NGHTTP2_STATIC_TABLE_LENGTH; ++i) {
nghttp2_hd_entry *ent = &static_table[i];
if(ent->name_hash != name_hash || !name_eq(&ent->nv, nv)) {
......@@ -860,24 +881,6 @@ static search_result search_hd_table(nghttp2_hd_context *context,
}
}
if(!use_index) {
return res;
}
for(i = 0; i < context->hd_table.len; ++i) {
nghttp2_hd_entry *ent = hd_ringbuf_get(&context->hd_table, i);
if(ent->name_hash == name_hash && name_eq(&ent->nv, nv)) {
if(res.index == -1) {
res.index = (ssize_t)(i + NGHTTP2_STATIC_TABLE_LENGTH);
}
if(ent->value_hash == value_hash && value_eq(&ent->nv, nv)) {
res.index = (ssize_t)(i + NGHTTP2_STATIC_TABLE_LENGTH);
res.name_value_match = 1;
return res;
}
}
}
return res;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment