AmendHub

Download:

jcs

/

amend

/

amendments

/

251

bile+repo: Faster sorts


jcs made amendment 251 about 1 year ago
--- bile.c Tue Apr 18 16:09:34 2023 +++ bile.c Tue Sep 19 20:45:17 2023 @@ -326,13 +326,13 @@ bile_sorted_ids_by_type(struct bile *bile, const OSTyp ids[count++] = o->id; } - for (n = 0; n < count; n++) { - for (j = 0; j < count - n - 1; j++) { - if (ids[j] > ids[j + 1]) { - t = ids[j]; - ids[j] = ids[j + 1]; - ids[j + 1] = t; - } + for (n = 1; n < count; n++) { + for (j = n; j > 0; j--) { + t = ids[j]; + if (t > ids[j - 1]) + break; + ids[j] = ids[j - 1]; + ids[j - 1] = t; } } --- repo.c Thu May 4 17:22:13 2023 +++ repo.c Tue Sep 19 20:44:45 2023 @@ -721,14 +721,16 @@ repo_sort_files(struct repo *repo) struct repo_file *file; short i, j; - for (i = 0; i < repo->nfiles; i++) { - for (j = 0; j < repo->nfiles - i - 1; j++) { - if (strnatcasecmp(repo->files[j]->filename, - repo->files[j + 1]->filename) == 1) { - file = repo->files[j]; - repo->files[j] = repo->files[j + 1]; - repo->files[j + 1] = file; - } + for (i = 1; i < repo->nfiles; i++) { + for (j = i; j > 0; j--) { + file = repo->files[j]; + + if (strnatcasecmp(file->filename, + repo->files[j - 1]->filename) == 1) + break; + + repo->files[j] = repo->files[j - 1]; + repo->files[j - 1] = file; } } }