From b48ceac56c9bf5283ea17f48edf86f7ed7fe1106 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 27 Sep 2014 23:08:14 +0900 Subject: [PATCH] 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. --- lib/nghttp2_hd.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index 98c01813..827f7711 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -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; }