From d952ec7ae90a85673c07a827e92f3c96a33725c1 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 2 Nov 2011 23:42:02 -0400 Subject: Simplify loop condition in PR-tree traversal. Doing this used to actually generate *worse* code, but now it looks like it generates much better code. --- libdimension/prtree.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libdimension/prtree.c b/libdimension/prtree.c index cfcc5a8..c59bcc4 100644 --- a/libdimension/prtree.c +++ b/libdimension/prtree.c @@ -628,9 +628,8 @@ dmnsn_prtree_intersection(const dmnsn_prtree *tree, dmnsn_line ray, /* Search the bounded objects */ dmnsn_flat_prnode *node = dmnsn_array_first(tree->bounded); - while ((size_t)(node - (dmnsn_flat_prnode *)dmnsn_array_first(tree->bounded)) - < dmnsn_array_size(tree->bounded)) - { + dmnsn_flat_prnode *last = dmnsn_array_last(tree->bounded); + while (node <= last) { if (dmnsn_ray_box_intersection(optline, node->bounding_box, t)) { if (node->object && node->object != cached) { if (dmnsn_closer_intersection(node->object, ray, intersection, &t)) { @@ -663,9 +662,8 @@ dmnsn_prtree_inside(const dmnsn_prtree *tree, dmnsn_vector point) /* Search the bounded objects */ dmnsn_flat_prnode *node = dmnsn_array_first(tree->bounded); - while ((size_t)(node - (dmnsn_flat_prnode *)dmnsn_array_first(tree->bounded)) - < dmnsn_array_size(tree->bounded)) - { + dmnsn_flat_prnode *last = dmnsn_array_last(tree->bounded); + while (node <= last) { if (dmnsn_bounding_box_contains(node->bounding_box, point)) { if (node->object && dmnsn_object_inside(node->object, point)) { return true; -- cgit v1.2.3