]> thyrsus.com Git - comparator.git/commitdiff
Compact for faster qsort.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 12 Sep 2003 03:48:23 +0000 (03:48 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 12 Sep 2003 03:48:23 +0000 (03:48 +0000)
report.c

index ba177a5002dfd704429a42419f67808a2236b9f4..d614b71d2d8f54a54880430ca1e09dfba2c15bd6 100644 (file)
--- a/report.c
+++ b/report.c
@@ -283,7 +283,7 @@ static int sortmatch(const void *a, const void *b)
 void emit_report(struct sorthash_t *obarray, int hashcount)
 /* report our results */
 {
-    struct match_t *hitlist, *match;
+    struct match_t *hitlist, *match, *copy;
     int mergecount;
 
     hitlist = reduce_matches(obarray, &hashcount);
@@ -292,20 +292,27 @@ void emit_report(struct sorthash_t *obarray, int hashcount)
     report_time("%d range groups after merging", mergecount);
     report_time("Reduction done");
 
-    qsort(hitlist, hashcount, sizeof(struct match_t), sortmatch);
-    for (match = hitlist; match < hitlist + hashcount; match++)
-       if (match->nmatches)
-       {
-           int i;
+    /*
+     * A little extra effort so we can generate a sirted report.
+     * Compact the match list in order to cut the n log n qsort time
+     */
+    for (copy = match = hitlist; match < hitlist + hashcount; match++)
+       if (match->nmatches && copy < match)
+           *copy++ = *match;
+    qsort(hitlist, mergecount, sizeof(struct match_t), sortmatch);
 
-           for (i=0; i < match->nmatches; i++)
-           {
-               struct sorthash_t       *rp = match->matches+i;
+    for (match = hitlist; match < hitlist + mergecount; match++)
+    {
+       int     i;
 
-               printf("%s:%d:%d\n",  rp->file, rp->hash.start, rp->hash.end);
-           }
-           printf("%%%%\n");
+       for (i=0; i < match->nmatches; i++)
+       {
+           struct sorthash_t   *rp = match->matches+i;
+
+           printf("%s:%d:%d\n",  rp->file, rp->hash.start, rp->hash.end);
        }
+       printf("%%%%\n");
+    }
     /* free(hitlist); */
 }