Commit 502ff245 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Avoid iterate siblings when adding/removing stream tree

parent 47692d11
......@@ -601,10 +601,37 @@ void nghttp2_stream_dep_insert(nghttp2_stream *dep_stream,
++stream->roots->num_streams;
}
static void link_dep(nghttp2_stream *dep_stream, nghttp2_stream *stream)
{
dep_stream->dep_next = stream;
stream->dep_prev = dep_stream;
}
static void link_sib(nghttp2_stream *prev_stream, nghttp2_stream *stream)
{
prev_stream->sib_next = stream;
stream->sib_prev = prev_stream;
}
static void insert_link_dep(nghttp2_stream *dep_stream,
nghttp2_stream *stream)
{
nghttp2_stream *sib_next;
assert(stream->sib_prev == NULL);
sib_next = dep_stream->dep_next;
link_sib(stream, sib_next);
sib_next->dep_prev = NULL;
link_dep(dep_stream, stream);
}
void nghttp2_stream_dep_add(nghttp2_stream *dep_stream,
nghttp2_stream *stream)
{
nghttp2_stream *last_sib;
nghttp2_stream *root_stream;
assert(stream->data_item == NULL);
......@@ -622,9 +649,7 @@ void nghttp2_stream_dep_add(nghttp2_stream *dep_stream,
dep_stream->dep_next = stream;
stream->dep_prev = dep_stream;
} else {
last_sib = stream_last_sib(dep_stream->dep_next);
last_sib->sib_next = stream;
stream->sib_prev = last_sib;
insert_link_dep(dep_stream, stream);
}
stream_update_dep_sum_norest_weight(root_stream);
......@@ -813,7 +838,6 @@ int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream,
nghttp2_pq *pq,
uint64_t cycle)
{
nghttp2_stream *last_sib;
nghttp2_stream *root_stream;
DEBUGF(fprintf(stderr, "stream: dep_add_subtree dep_stream(%p)=%d "
......@@ -826,10 +850,7 @@ int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream,
if(dep_stream->dep_next) {
dep_stream->sum_dep_weight += stream->weight;
last_sib = stream_last_sib(dep_stream->dep_next);
last_sib->sib_next = stream;
stream->sib_prev = last_sib;
insert_link_dep(dep_stream, stream);
} else {
dep_stream->dep_next = stream;
stream->dep_prev = dep_stream;
......@@ -961,12 +982,14 @@ int nghttp2_stream_dep_all_your_stream_are_belong_to_us
}
if(stream->dep_next) {
nghttp2_stream *last_sib;
nghttp2_stream *sib_next;
last_sib = stream_last_sib(stream->dep_next);
sib_next = stream->dep_next;
sib_next->dep_prev = NULL;
last_sib->sib_next = first;
first->sib_prev = last_sib;
link_sib(first, sib_next);
link_dep(stream, prev);
} else {
stream->dep_next = first;
first->dep_prev = stream;
......
......@@ -5339,8 +5339,8 @@ void test_nghttp2_session_stream_dep_add(void)
a = open_stream(session, 1);
b = open_stream_with_dep(session, 3, a);
c = open_stream_with_dep(session, 5, a);
b = open_stream_with_dep(session, 3, a);
d = open_stream_with_dep(session, 7, c);
/* a
......@@ -5423,9 +5423,9 @@ void test_nghttp2_session_stream_dep_remove(void)
/* a
* |
* b--c
* |
* d
* c--b
* |
* d
*/
nghttp2_stream_dep_remove(a);
......@@ -5452,9 +5452,9 @@ void test_nghttp2_session_stream_dep_remove(void)
check_stream_dep_sib(d, c, NULL, NULL, NULL);
CU_ASSERT(3 == session->roots.num_streams);
CU_ASSERT(c == session->roots.head);
CU_ASSERT(b == c->root_next);
CU_ASSERT(NULL == b->root_next);
CU_ASSERT(b == session->roots.head);
CU_ASSERT(c == b->root_next);
CU_ASSERT(NULL == c->root_next);
nghttp2_session_del(session);
......@@ -5468,9 +5468,9 @@ void test_nghttp2_session_stream_dep_remove(void)
/* a
* |
* b--c
* |
* d
* c--b
* |
* d
*/
nghttp2_stream_dep_remove(b);
......@@ -5514,9 +5514,9 @@ void test_nghttp2_session_stream_dep_remove(void)
/* a
* |
* b--c
* |
* d
* c--b
* |
* d
*/
nghttp2_stream_dep_remove(c);
......@@ -5524,7 +5524,7 @@ void test_nghttp2_session_stream_dep_remove(void)
/* becomes:
* a
* |
* b--d
* d--b
*/
CU_ASSERT(3 == a->num_substreams);
......@@ -5537,10 +5537,10 @@ void test_nghttp2_session_stream_dep_remove(void)
CU_ASSERT(0 == d->sum_dep_weight);
CU_ASSERT(0 == c->sum_dep_weight);
check_stream_dep_sib(a, NULL, b, NULL, NULL);
check_stream_dep_sib(b, a, NULL, NULL, d);
check_stream_dep_sib(a, NULL, d, NULL, NULL);
check_stream_dep_sib(b, NULL, NULL, d, NULL);
check_stream_dep_sib(c, NULL, NULL, NULL, NULL);
check_stream_dep_sib(d, NULL, NULL, b, NULL);
check_stream_dep_sib(d, a, NULL, NULL, b);
nghttp2_session_del(session);
......@@ -5556,9 +5556,9 @@ void test_nghttp2_session_stream_dep_remove(void)
/* a
* |
* b--c--d
* d--c--b
* |
* e--f
* f--e
*/
CU_ASSERT(6 == a->num_substreams);
......@@ -5580,7 +5580,7 @@ void test_nghttp2_session_stream_dep_remove(void)
/* becomes:
* a
* |
* b--e--f--d
* d--f--e--b
*/
CU_ASSERT(5 == a->num_substreams);
......@@ -5599,12 +5599,12 @@ void test_nghttp2_session_stream_dep_remove(void)
CU_ASSERT(0 == e->sum_dep_weight);
CU_ASSERT(0 == f->sum_dep_weight);
check_stream_dep_sib(a, NULL, b, NULL, NULL);
check_stream_dep_sib(b, a, NULL, NULL, e);
check_stream_dep_sib(a, NULL, d, NULL, NULL);
check_stream_dep_sib(b, NULL, NULL, e, NULL);
check_stream_dep_sib(c, NULL, NULL, NULL, NULL);
check_stream_dep_sib(e, NULL, NULL, b, f);
check_stream_dep_sib(f, NULL, NULL, e, d);
check_stream_dep_sib(d, NULL, NULL, f, NULL);
check_stream_dep_sib(e, NULL, NULL, f, b);
check_stream_dep_sib(f, NULL, NULL, d, e);
check_stream_dep_sib(d, a, NULL, NULL, f);
nghttp2_session_del(session);
}
......@@ -5630,9 +5630,9 @@ void test_nghttp2_session_stream_dep_add_subtree(void)
/* a e
* | |
* b--c f
* |
* d
* c--b f
* |
* d
*/
nghttp2_stream_dep_add_subtree(a, e, &session->ob_da_pq,
......@@ -5641,9 +5641,9 @@ void test_nghttp2_session_stream_dep_add_subtree(void)
/* becomes
* a
* |
* b--c--e
* | |
* d f
* e--c--b
* | |
* f d
*/
CU_ASSERT(6 == a->num_substreams);
......@@ -5660,11 +5660,11 @@ void test_nghttp2_session_stream_dep_add_subtree(void)
CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == e->sum_dep_weight);
CU_ASSERT(0 == f->sum_dep_weight);
check_stream_dep_sib(a, NULL, b, NULL, NULL);
check_stream_dep_sib(b, a, NULL, NULL, c);
check_stream_dep_sib(c, NULL, d, b, e);
check_stream_dep_sib(a, NULL, e, NULL, NULL);
check_stream_dep_sib(b, NULL, NULL, c, NULL);
check_stream_dep_sib(c, NULL, d, e, b);
check_stream_dep_sib(d, c, NULL, NULL, NULL);
check_stream_dep_sib(e, NULL, f, c, NULL);
check_stream_dep_sib(e, a, f, NULL, c);
check_stream_dep_sib(f, e, NULL, NULL, NULL);
nghttp2_session_del(session);
......@@ -5682,9 +5682,9 @@ void test_nghttp2_session_stream_dep_add_subtree(void)
/* a e
* | |
* b--c f
* |
* d
* c--b f
* |
* d
*/
nghttp2_stream_dep_insert_subtree(a, e, &session->ob_da_pq,
......@@ -5695,9 +5695,9 @@ void test_nghttp2_session_stream_dep_add_subtree(void)
* |
* e
* |
* f--b--c
* |
* d
* f--c--b
* |
* d
*/
CU_ASSERT(6 == a->num_substreams);
......@@ -5716,9 +5716,9 @@ void test_nghttp2_session_stream_dep_add_subtree(void)
check_stream_dep_sib(a, NULL, e, NULL, NULL);
check_stream_dep_sib(e, a, f, NULL, NULL);
check_stream_dep_sib(f, e, NULL, NULL, b);
check_stream_dep_sib(b, NULL, NULL, f, c);
check_stream_dep_sib(c, NULL, d, b, NULL);
check_stream_dep_sib(f, e, NULL, NULL, c);
check_stream_dep_sib(b, NULL, NULL, c, NULL);
check_stream_dep_sib(c, NULL, d, f, b);
check_stream_dep_sib(d, c, NULL, NULL, NULL);
nghttp2_session_del(session);
......@@ -5742,9 +5742,9 @@ void test_nghttp2_session_stream_dep_remove_subtree(void)
/* a
* |
* b--c
* |
* d
* c--b
* |
* d
*/
nghttp2_stream_dep_remove_subtree(c);
......@@ -5782,9 +5782,9 @@ void test_nghttp2_session_stream_dep_remove_subtree(void)
/* a
* |
* b--c
* |
* d
* c--b
* |
* d
*/
nghttp2_stream_dep_remove_subtree(b);
......@@ -5818,10 +5818,10 @@ void test_nghttp2_session_stream_dep_remove_subtree(void)
nghttp2_session_server_new(&session, &callbacks, NULL);
a = open_stream(session, 1);
b = open_stream_with_dep(session, 3, a);
e = open_stream_with_dep(session, 9, a);
c = open_stream_with_dep(session, 5, a);
b = open_stream_with_dep(session, 3, a);
d = open_stream_with_dep(session, 7, c);
e = open_stream_with_dep(session, 9, a);
/* a
* |
......@@ -5961,9 +5961,9 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void)
/*
* c
* |
* d--a
* |
* b
* a--d
* |
* b
*/
CU_ASSERT(4 == c->num_substreams);
......@@ -5976,9 +5976,9 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void)
CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight);
CU_ASSERT(0 == b->sum_dep_weight);
check_stream_dep_sib(c, NULL, d, NULL, NULL);
check_stream_dep_sib(d, c, NULL, NULL, a);
check_stream_dep_sib(a, NULL, b, d, NULL);
check_stream_dep_sib(c, NULL, a, NULL, NULL);
check_stream_dep_sib(d, NULL, NULL, a, NULL);
check_stream_dep_sib(a, c, b, NULL, d);
check_stream_dep_sib(b, a, NULL, NULL, NULL);
nghttp2_session_del(session);
......@@ -6002,9 +6002,9 @@ void test_nghttp2_session_stream_attach_data(void)
/* a
* |
* b--c
* |
* d
* c--b
* |
* d
*/
db = create_data_ob_item();
......@@ -6121,9 +6121,9 @@ void test_nghttp2_session_stream_attach_data_subtree(void)
/*
* a e
* | |
* b--c f
* |
* d
* c--b f
* |
* d
*/
de = create_data_ob_item();
......@@ -6155,9 +6155,9 @@ void test_nghttp2_session_stream_attach_data_subtree(void)
* |
* e
* |
* f--b--c
* |
* d
* f--c--b
* |
* d
*/
CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_DATA == a->dpri);
......@@ -6242,9 +6242,9 @@ void test_nghttp2_session_stream_attach_data_subtree(void)
/*
* a b
* |
* e--c
* c--e
* | |
* f d
* d f
*/
CU_ASSERT(NGHTTP2_STREAM_DPRI_NO_DATA == a->dpri);
......
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