~ubuntu-branches/ubuntu/lucid/sreadahead/lucid

« back to all changes in this revision

Viewing changes to sreadahead.c

  • Committer: Bazaar Package Importer
  • Author(s): Anders Kaseorg
  • Date: 2009-09-20 13:31:45 UTC
  • Revision ID: james.westby@ubuntu.com-20090920133145-lnomws4ckhdul8ml
Tags: 1.0-4
Replace custom bubble sort with qsort(), to avoid using 100% CPU
for a long time after boot.  LP: #421116, #434116.

Show diffs side-by-side

added added

removed removed

Lines of Context:
187
187
        return NULL;
188
188
}
189
189
 
 
190
static int compare_ras_by_name(const void *memb1, const void *memb2)
 
191
{
 
192
        struct ra_struct *const *ra1 = memb1, *const *ra2 = memb2;
 
193
        int c = strcmp((*ra1)->filename, (*ra2)->filename);
 
194
 
 
195
        if (c != 0)
 
196
                return c;
 
197
 
 
198
        /* Leave equal filenames in the original order. */
 
199
        return (*ra1)->number - (*ra2)->number;
 
200
}
 
201
 
190
202
static void sort_ra_by_name(void)
191
203
{
192
 
        int delta = 1;
193
 
 
194
 
        while (delta > 0) {
195
 
                int i;
196
 
                delta = 0;
197
 
                for (i = 0; i < racount - 1; i++) {
198
 
                        int c;
199
 
 
200
 
                        c = strcmp(ra[i]->filename, ra[i+1]->filename);
201
 
                        if (c > 0) {
202
 
                                struct ra_struct *tmp;
203
 
                                tmp = ra[i];
204
 
                                ra[i] = ra[i+1];
205
 
                                ra[i+1] = tmp;
206
 
                                delta++;
207
 
                        }
208
 
                }
209
 
        }
 
204
        qsort(ra, racount, sizeof(*ra), compare_ras_by_name);
210
205
}
211
206
 
212
207
static void remove_dupes(void)