AmendHub

Download:

jcs

/

subtext

/

amendments

/

525

board: Faster sorts


jcs made amendment 525 about 1 year ago
--- board.c Thu Aug 3 09:46:08 2023 +++ board.c Tue Sep 19 21:09:07 2023 @@ -193,13 +193,14 @@ board_list_boards(struct session *s) } /* sort by board name */ - for (i = 0; i < nlboards; i++) { - for (j = 0; j < nlboards - i - 1; j++) { - if (strcmp(lboards[j].name, lboards[j + 1].name) > 0) { - tboard = lboards[j]; - lboards[j] = lboards[j + 1]; - lboards[j + 1] = tboard; - } + for (i = 1; i < nlboards; i++) { + for (j = i; j > 0; j--) { + tboard = lboards[j]; + if (strcmp(lboards[j].name, lboards[j - 1].name) > 0) + break; + tboard = lboards[j]; + lboards[j] = lboards[j - 1]; + lboards[j - 1] = tboard; } } @@ -300,14 +301,13 @@ board_list_ftn_areas(struct session *s) } /* sort by area name */ - for (i = 0; i < nfboards; i++) { - for (j = 0; j < nfboards - i - 1; j++) { - if (strcmp(fboards[j].ftn_area, - fboards[j + 1].ftn_area) > 0) { - tboard = fboards[j]; - fboards[j] = fboards[j + 1]; - fboards[j + 1] = tboard; - } + for (i = 1; i < nfboards; i++) { + for (j = i; j > 0; j--) { + if (strcmp(fboards[j].ftn_area, fboards[j - 1].ftn_area) > 0) + break; + tboard = fboards[j]; + fboards[j] = fboards[j - 1]; + fboards[j - 1] = tboard; } } @@ -1577,13 +1577,13 @@ board_index_sorted_post_ids(struct board *board, } /* sort by date descending */ - for (i = 0; i < npost_ids; i++) { - for (j = 0; j < npost_ids - i - 1; j++) { - if (id_map[j].time < id_map[j + 1].time) { - tmp_id_map = id_map[j]; - id_map[j] = id_map[j + 1]; - id_map[j + 1] = tmp_id_map; - } + for (i = 1; i < npost_ids; i++) { + for (j = i; j > 0; j--) { + if (id_map[j].time < id_map[j - 1].time) + break; + tmp_id_map = id_map[j]; + id_map[j] = id_map[j - 1]; + id_map[j - 1] = tmp_id_map; } } } else { @@ -1616,13 +1616,13 @@ board_index_sorted_post_ids(struct board *board, xfree(&thread_ids); /* sort by last post date descending */ - for (i = 0; i < nthread_ids; i++) { - for (j = 0; j < nthread_ids - i - 1; j++) { - if (thread_map[j].time < thread_map[j + 1].time) { - tmp_thread_map = thread_map[j]; - thread_map[j] = thread_map[j + 1]; - thread_map[j + 1] = tmp_thread_map; - } + for (i = 1; i < nthread_ids; i++) { + for (j = i; j > 0; j--) { + if (thread_map[j].time < thread_map[j - 1].time) + break; + tmp_thread_map = thread_map[j]; + thread_map[j] = thread_map[j - 1]; + thread_map[j - 1] = tmp_thread_map; } }