Fill queue is now actually a stack
Size of queue structure (which contains 3 ints, so is 12 bytes on my Linux laptop) before & after, when filling a few sample images when running in a 3000x2000 window: * a pattern i drew queue: 855,040 stack: 287,744 * mosaic queue: 908,288 stack: 398,336 * mosaic 4x via panel magic tool queue: 1,451,008 stack: 734,208
This commit is contained in:
parent
0431cce21f
commit
e77c7766cd
1 changed files with 9 additions and 11 deletions
20
src/fill.c
20
src/fill.c
|
|
@ -69,7 +69,7 @@ typedef struct queue_s {
|
|||
} queue_t;
|
||||
|
||||
queue_t * queue;
|
||||
int queue_size = 0, queue_start = 0, queue_end = 0;
|
||||
int queue_size = 0, queue_end = 0;
|
||||
|
||||
/* Local function prototypes: */
|
||||
|
||||
|
|
@ -91,7 +91,6 @@ void cleanup_queue(void);
|
|||
|
||||
void init_queue(void) {
|
||||
queue_size = 0;
|
||||
queue_start = 0;
|
||||
queue_end = 0;
|
||||
|
||||
queue = (queue_t *) malloc(sizeof(queue_t) * QUEUE_SIZE_CHUNK);
|
||||
|
|
@ -139,19 +138,19 @@ void add_to_queue(int x, int y, int y_outside) {
|
|||
}
|
||||
|
||||
int remove_from_queue(int * x, int * y, int * y_outside) {
|
||||
if (queue_start == queue_end)
|
||||
if (queue_end == 0)
|
||||
return 0;
|
||||
|
||||
*x = queue[queue_start].x;
|
||||
*y = queue[queue_start].y;
|
||||
*y_outside = queue[queue_start].y_outside;
|
||||
queue_end--;
|
||||
|
||||
queue_start++;
|
||||
*x = queue[queue_end].x;
|
||||
*y = queue[queue_end].y;
|
||||
*y_outside = queue[queue_end].y_outside;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (queue_start % 100 == 0)
|
||||
if (queue_end % 100 == 0)
|
||||
{
|
||||
printf("queue_start = %d\n", queue_start);
|
||||
printf("queue_end = %d\n", queue_end);
|
||||
fflush(stdout);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -164,11 +163,10 @@ void cleanup_queue(void) {
|
|||
free(queue);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("queue_size = %d\n\n", queue_size);
|
||||
printf("Final size was %d\n", queue_size);
|
||||
#endif
|
||||
|
||||
queue_size = 0;
|
||||
queue_start = 0;
|
||||
queue_end = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue