llvmpipe: Refactor lp_scene_add_resource_reference

Less goto spaghetti.
This commit is contained in:
José Fonseca 2010-08-26 12:09:53 +01:00 committed by Keith Whitwell
parent 9cd45b8edf
commit a7c4541d27
1 changed files with 15 additions and 14 deletions

View File

@ -344,6 +344,7 @@ lp_scene_add_resource_reference(struct lp_scene *scene,
/* Look at existing resource blocks: /* Look at existing resource blocks:
*/ */
for (ref = scene->resources; ref; ref = ref->next) { for (ref = scene->resources; ref; ref = ref->next) {
last = &ref->next;
/* Search for this resource: /* Search for this resource:
*/ */
@ -351,27 +352,27 @@ lp_scene_add_resource_reference(struct lp_scene *scene,
if (ref->resource[i] == resource) if (ref->resource[i] == resource)
return TRUE; return TRUE;
/* If the block is half-empty, this is the last block. Append if (ref->count < RESOURCE_REF_SZ) {
* the reference here. /* If the block is half-empty, then append the reference here.
*/ */
if (ref->count < RESOURCE_REF_SZ) break;
goto add_new_ref; }
last = &ref->next;
} }
/* 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 (!ref) {
if (*last) { assert(*last == NULL);
*last = lp_scene_alloc(scene, sizeof *ref);
if (*last == NULL)
return FALSE;
ref = *last; ref = *last;
memset(ref, 0, sizeof *ref); memset(ref, 0, sizeof *ref);
goto add_new_ref;
} }
return FALSE; /* Append the reference to the reference block.
*/
add_new_ref:
pipe_resource_reference(&ref->resource[ref->count++], resource); pipe_resource_reference(&ref->resource[ref->count++], resource);
scene->resource_reference_size += llvmpipe_resource_size(resource); scene->resource_reference_size += llvmpipe_resource_size(resource);