Mesa (master): llvmpipe: Refactor lp_scene_add_resource_reference

Keith Whitwell keithw at kemper.freedesktop.org
Tue Sep 7 13:03:40 UTC 2010


Module: Mesa
Branch: master
Commit: a7c4541d272d5dc11e4cfe0a2dcaf42f0b98a50e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a7c4541d272d5dc11e4cfe0a2dcaf42f0b98a50e

Author: José Fonseca <jfonseca at vmware.com>
Date:   Thu Aug 26 12:09:53 2010 +0100

llvmpipe: Refactor lp_scene_add_resource_reference

Less goto spaghetti.

---

 src/gallium/drivers/llvmpipe/lp_scene.c |   29 +++++++++++++++--------------
 1 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c b/src/gallium/drivers/llvmpipe/lp_scene.c
index c7e3c59..f6c6941 100644
--- a/src/gallium/drivers/llvmpipe/lp_scene.c
+++ b/src/gallium/drivers/llvmpipe/lp_scene.c
@@ -344,6 +344,7 @@ lp_scene_add_resource_reference(struct lp_scene *scene,
    /* Look at existing resource blocks:
     */
    for (ref = scene->resources; ref; ref = ref->next) {
+      last = &ref->next;
 
       /* Search for this resource:
        */
@@ -351,27 +352,27 @@ lp_scene_add_resource_reference(struct lp_scene *scene,
          if (ref->resource[i] == resource)
             return TRUE;
 
-      /* If the block is half-empty, this is the last block.  Append
-       * the reference here.
-       */
-      if (ref->count < RESOURCE_REF_SZ)
-         goto add_new_ref;
-
-      last = &ref->next;
+      if (ref->count < RESOURCE_REF_SZ) {
+         /* If the block is half-empty, then append the reference here.
+          */
+         break;
+      }
    }
 
-   /* Otherwise, need to create a new block:
+   /* Create a new block if no half-empty block was found.
     */
-   *last = lp_scene_alloc(scene, sizeof(struct resource_ref));
-   if (*last) {
+   if (!ref) {
+      assert(*last == NULL);
+      *last = lp_scene_alloc(scene, sizeof *ref);
+      if (*last == NULL)
+          return FALSE;
+
       ref = *last;
       memset(ref, 0, sizeof *ref);
-      goto add_new_ref;
    }
 
-   return FALSE;
-
-add_new_ref:
+   /* Append the reference to the reference block.
+    */
    pipe_resource_reference(&ref->resource[ref->count++], resource);
    scene->resource_reference_size += llvmpipe_resource_size(resource);
 




More information about the mesa-commit mailing list