app: improvements in code executed a lot while painting.

This keeps the same rectangle packing behaviour, so to behave exactly as
before for what concerns batching the updates, but should be lighter
when looping to find the first good rectangle to use.

In rtree_insert(), some conditions in the if tests are implied by
previous conditions. And therefore the 2 successive for loops are
actually identical.

In rtree_node_insert(), it is wrong/harmful to insert zero sized
rectangles in the tree because they can never be selected and just make
the list longer. So rtree_node_create() should just return NULL when w
or h are 0.

See bug 694917, comments 51 to 61.
This commit is contained in:
Massimo Valentini
2018-03-29 16:50:15 +02:00
committed by Jehan
parent 31086ae211
commit 2aa4426d4f

View File

@ -72,10 +72,11 @@ rtree_node_create (RTree *rtree,
gimp_assert (x >= 0 && x+w <= rtree->root.w);
gimp_assert (y >= 0 && y+h <= rtree->root.h);
node = g_slice_alloc (sizeof (*node));
if (node == NULL)
if (w <= 0 || h <= 0)
return NULL;
node = g_slice_alloc (sizeof (*node));
node->children[0] = NULL;
node->children[1] = NULL;
node->x = x;
@ -148,10 +149,6 @@ rtree_insert (RTree *rtree,
{
RTreeNode *node, **prev;
for (prev = &rtree->available; (node = *prev); prev = &node->next)
if (node->w >= w && w < 2 * node->w && node->h >= h && h < 2 * node->h)
return rtree_node_insert (rtree, prev, node, w, h);
for (prev = &rtree->available; (node = *prev); prev = &node->next)
if (node->w >= w && node->h >= h)
return rtree_node_insert (rtree, prev, node, w, h);