jcs
/subtext
/amendments
/527
mail: Faster sort
jcs made amendment 527 about 1 year ago
--- mail.c Fri Apr 7 14:11:21 2023
+++ mail.c Wed Sep 20 08:41:06 2023
@@ -805,13 +805,13 @@ mail_find_ids_for_user(struct user *user, size_t *nret
if (ret_mail_ids != NULL) {
/* sort by message id descending for consistent ordering */
- for (i = 0; i < nmail_ids; i++) {
- for (j = 0; j < nmail_ids - i - 1; j++) {
- if (mail_ids[j] < mail_ids[j + 1]) {
- id = mail_ids[j];
- mail_ids[j] = mail_ids[j + 1];
- mail_ids[j + 1] = id;
- }
+ for (i = 1; i < nmail_ids; i++) {
+ for (j = i; j > 0; j--) {
+ if (mail_ids[j] < mail_ids[j - 1])
+ break;
+ id = mail_ids[j];
+ mail_ids[j] = mail_ids[j - 1];
+ mail_ids[j - 1] = id;
}
}
}