summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-11-02 23:42:02 -0400
committerTavian Barnes <tavianator@gmail.com>2011-11-03 11:38:14 -0400
commitd952ec7ae90a85673c07a827e92f3c96a33725c1 (patch)
treea5cc4e0b0d1cabb33eb3a4e3adb03847c5d534c4
parentf33fb7eeb3d5d354a991089053a158dcb5e724c1 (diff)
downloaddimension-d952ec7ae90a85673c07a827e92f3c96a33725c1.tar.xz
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.
-rw-r--r--libdimension/prtree.c10
1 files 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;