From 2d4e1e5e0add5a33b3744d7d149a1e1dc4aa4513 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:34:50 +0100 Subject: [PATCH 01/15] dc: convert to infinite loop Signed-off-by: Frediano Ziglio --- server/display-channel.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/display-channel.c b/server/display-channel.c index 13be9472..72ce1458 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -481,7 +481,10 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * while (link) { dcc = link->data; dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); - while (link && (!dpi || dcc != dpi->dcc)) { + for (;;) { + if (!link || (dpi && dcc == dpi->dcc)) { + break; + } dcc_prepend_drawable(dcc, drawable); link = link->next; if (link) From a5a9b38f461495a7997ecfd13a49dce0e3924040 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:35:42 +0100 Subject: [PATCH 02/15] dc: split if Signed-off-by: Frediano Ziglio --- server/display-channel.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/display-channel.c b/server/display-channel.c index 72ce1458..e544be9f 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -482,7 +482,10 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * dcc = link->data; dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); for (;;) { - if (!link || (dpi && dcc == dpi->dcc)) { + if (!link) { + break; + } + if (dpi && dcc == dpi->dcc) { break; } dcc_prepend_drawable(dcc, drawable); From 1d39275c3dd03a96842486e4117ee3e376ba1f5a Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:38:33 +0100 Subject: [PATCH 03/15] dc: the link condition make this case terminate loop dpi_ring_item is changed but ignored Signed-off-by: Frediano Ziglio --- server/display-channel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/display-channel.c b/server/display-channel.c index e544be9f..437bf8da 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -483,7 +483,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); for (;;) { if (!link) { - break; + goto out_loop; } if (dpi && dcc == dpi->dcc) { break; @@ -501,6 +501,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * link = link->next; } } +out_loop: /* not sending other_drawable where possible */ drawable_remove_from_pipes(other_drawable); From a3ad49b326d4b2df330e0b3f46c7876b9f8fd504 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:39:52 +0100 Subject: [PATCH 04/15] dc: link is never null here Signed-off-by: Frediano Ziglio --- server/display-channel.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index 437bf8da..da295c20 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -497,9 +497,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * if (dpi_ring_item) { dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); } - if (link) { - link = link->next; - } + link = link->next; } out_loop: /* not sending other_drawable where possible */ From 7447a9e66c6ef15ce8d3435aaeb240430e6f3247 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:41:41 +0100 Subject: [PATCH 05/15] dc: dcc used is always a value from current link Signed-off-by: Frediano Ziglio --- server/display-channel.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index da295c20..6242e482 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -479,19 +479,17 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * dpi_ring_item = ring_get_head(&other_drawable->pipes); /* dpi contains a sublist of dcc's, ordered the same */ while (link) { - dcc = link->data; dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); for (;;) { if (!link) { goto out_loop; } + dcc = link->data; if (dpi && dcc == dpi->dcc) { break; } dcc_prepend_drawable(dcc, drawable); link = link->next; - if (link) - dcc = link->data; } if (dpi_ring_item) { From dec4b7eca5d0a8764a439b2919ac3610b1f0b0a3 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:44:33 +0100 Subject: [PATCH 06/15] dc: move code inside if these lines are only executed then the condition are satisfied Signed-off-by: Frediano Ziglio --- server/display-channel.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index 6242e482..512eafa7 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -486,16 +486,15 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * } dcc = link->data; if (dpi && dcc == dpi->dcc) { + if (dpi_ring_item) { + dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); + } + link = link->next; break; } dcc_prepend_drawable(dcc, drawable); link = link->next; } - - if (dpi_ring_item) { - dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); - } - link = link->next; } out_loop: /* not sending other_drawable where possible */ From 643bf445c59adf475d99d523ea3b677cf4ae7ecc Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:46:50 +0100 Subject: [PATCH 07/15] dc: dpi is always a value computed from dpi_ring_item Signed-off-by: Frediano Ziglio --- server/display-channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/display-channel.c b/server/display-channel.c index 512eafa7..8fbd36e4 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -479,12 +479,12 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * dpi_ring_item = ring_get_head(&other_drawable->pipes); /* dpi contains a sublist of dcc's, ordered the same */ while (link) { - dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); for (;;) { if (!link) { goto out_loop; } dcc = link->data; + dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); if (dpi && dcc == dpi->dcc) { if (dpi_ring_item) { dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); From 9a85e3cf343dc4bc059380a1c5a975f26ef63200 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:49:44 +0100 Subject: [PATCH 08/15] dc: if dpi is not NULL even dpi_ring_item is not NULL Signed-off-by: Frediano Ziglio --- server/display-channel.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index 8fbd36e4..70cbe88d 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -486,9 +486,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * dcc = link->data; dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); if (dpi && dcc == dpi->dcc) { - if (dpi_ring_item) { - dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); - } + dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); link = link->next; break; } From 0010656ea4a201926f59b7d41641461b05752520 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:54:01 +0100 Subject: [PATCH 09/15] dc: if link is NULL jumping outside loop will check variable and exit The outer loop will exit too. Signed-off-by: Frediano Ziglio --- server/display-channel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index 70cbe88d..ef2b28d0 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -481,7 +481,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * while (link) { for (;;) { if (!link) { - goto out_loop; + break; } dcc = link->data; dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); @@ -494,7 +494,6 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * link = link->next; } } -out_loop: /* not sending other_drawable where possible */ drawable_remove_from_pipes(other_drawable); From 5fbac6c8cbd7d79971a0c547d93a442fefabcf49 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:55:14 +0100 Subject: [PATCH 10/15] dc: use while again Convert from for(;;) { if () break; ... } to while Signed-off-by: Frediano Ziglio --- server/display-channel.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index ef2b28d0..574ba57d 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -479,10 +479,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * dpi_ring_item = ring_get_head(&other_drawable->pipes); /* dpi contains a sublist of dcc's, ordered the same */ while (link) { - for (;;) { - if (!link) { - break; - } + while (link) { dcc = link->data; dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); if (dpi && dcc == dpi->dcc) { From a7b01620155bd58c5273bb7a644b57a0bc56e42e Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:58:22 +0100 Subject: [PATCH 11/15] dc: convert break to continue Both jump to check worker_ring_item (internal or external loops) Signed-off-by: Frediano Ziglio --- server/display-channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/display-channel.c b/server/display-channel.c index 574ba57d..10bd2a90 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -485,7 +485,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * if (dpi && dcc == dpi->dcc) { dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); link = link->next; - break; + continue; } dcc_prepend_drawable(dcc, drawable); link = link->next; From 85d3af793d636d8c4b8f3aeb1815420b80a250d2 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 13:59:08 +0100 Subject: [PATCH 12/15] dc: reuse code inside loop Signed-off-by: Frediano Ziglio --- server/display-channel.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index 10bd2a90..f3251f3b 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -484,10 +484,9 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); if (dpi && dcc == dpi->dcc) { dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); - link = link->next; - continue; + } else { + dcc_prepend_drawable(dcc, drawable); } - dcc_prepend_drawable(dcc, drawable); link = link->next; } } From 0c91530b07d2991293360ba72c391913049c7236 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 14:00:29 +0100 Subject: [PATCH 13/15] dc: join the two loop They tested the same condition, no break in inside loop (which would exit all loops) Signed-off-by: Frediano Ziglio --- server/display-channel.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index f3251f3b..a87d40a2 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -479,16 +479,14 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * dpi_ring_item = ring_get_head(&other_drawable->pipes); /* dpi contains a sublist of dcc's, ordered the same */ while (link) { - while (link) { - dcc = link->data; - dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); - if (dpi && dcc == dpi->dcc) { - dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); - } else { - dcc_prepend_drawable(dcc, drawable); - } - link = link->next; + dcc = link->data; + dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); + if (dpi && dcc == dpi->dcc) { + dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); + } else { + dcc_prepend_drawable(dcc, drawable); } + link = link->next; } /* not sending other_drawable where possible */ drawable_remove_from_pipes(other_drawable); From 25d4a665192574ec31e7b8ba7a3b14362e8d9889 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Sat, 14 May 2016 14:02:33 +0100 Subject: [PATCH 14/15] dc: inline dpi computation Actually not exactly the same as this fix a bug if base is not the first element (in this case if dpi_ring_item is NULL dpi is not) Signed-off-by: Frediano Ziglio --- server/display-channel.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index a87d40a2..1b1bea68 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -466,7 +466,6 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * if (is_same_drawable(drawable, other_drawable)) { DisplayChannelClient *dcc; - RedDrawablePipeItem *dpi; RingItem *dpi_ring_item; GList *link; @@ -480,8 +479,7 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * /* dpi contains a sublist of dcc's, ordered the same */ while (link) { dcc = link->data; - dpi = SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item); - if (dpi && dcc == dpi->dcc) { + if (dpi_ring_item && dcc == SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item)->dcc) { dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); } else { dcc_prepend_drawable(dcc, drawable); From ca5db16cb8451829bdfaf07e2d736fd45b4547d7 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Wed, 25 May 2016 09:29:44 +0100 Subject: [PATCH 15/15] dc: use FOREACH_CLIENT macro for loop Signed-off-by: Frediano Ziglio --- server/display-channel.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/server/display-channel.c b/server/display-channel.c index 1b1bea68..cfa182c3 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -467,24 +467,21 @@ static int current_add_equal(DisplayChannel *display, DrawItem *item, TreeItem * DisplayChannelClient *dcc; RingItem *dpi_ring_item; - GList *link; + GList *link, *next; other_drawable->refs++; current_remove_drawable(display, other_drawable); /* sending the drawable to clients that already received * (or will receive) other_drawable */ - link = RED_CHANNEL(display)->clients; dpi_ring_item = ring_get_head(&other_drawable->pipes); /* dpi contains a sublist of dcc's, ordered the same */ - while (link) { - dcc = link->data; + FOREACH_CLIENT(display, link, next, dcc) { if (dpi_ring_item && dcc == SPICE_UPCAST(RedDrawablePipeItem, dpi_ring_item)->dcc) { dpi_ring_item = ring_next(&other_drawable->pipes, dpi_ring_item); } else { dcc_prepend_drawable(dcc, drawable); } - link = link->next; } /* not sending other_drawable where possible */ drawable_remove_from_pipes(other_drawable);