jobs array

Michael Sweet mike at easysw.com
Mon Aug 2 10:38:03 PDT 2004


pieterjandeboeck at yahoo.co.uk wrote:
> ...
> Also I noticed you are counting down. I read somewhere it improves
> speed  although i never do it myself. Is it much better?

In general it can improve performance slightly for tight loops,
however in this case it simplifies the code a lot so you don't have
to do anything special when you decrement num_jobs, e.g.:

     for (i = 0; i < num_jobs; i ++)
       if (jobs[i].state == IPP_JOB_HELD)
       {
         if (i < (num_jobs - 1))
           memmove(...);

         num_jobs --;
         i --;
       }

Also, you can do less moving when parsing from right-to-left; that
is, let's take the following array of numbers:

     1 2 4 8 4 8

If we remove all of the 4's from the array from left to right, then
we will need to perform 3 + 1 = 4 copies total (first by moving
8 4 8 and then the last 8).

If we remove them from right to left, then we perform 1 + 2 = 3
copies total (first by moving the last 8 and then the remaining 8 8)

In general, when removing N items from an array, processing from
right to left will save you N-1 copies.

-- 
______________________________________________________________________
Michael Sweet, Easy Software Products           mike at easysw dot com
Printing Software for UNIX                       http://www.easysw.com




More information about the cups-devel mailing list