summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/dns.c
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2008-11-10 03:54:09 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2008-11-10 03:54:09 +0000
commita07e938a3cb6d6ef1b62e154c3c2815b741c98db (patch)
treeb23f1620c89a6f4f8c7e24e99db66aa2c8f500a9 /usr.sbin/smtpd/dns.c
parenta2c39ee12898912b086a5c76d063d1f5c4b5a490 (diff)
insertion sort is faster than bubble sort. ok gilles
Diffstat (limited to 'usr.sbin/smtpd/dns.c')
-rw-r--r--usr.sbin/smtpd/dns.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c
index 63de46a4bfd..8623f91ba35 100644
--- a/usr.sbin/smtpd/dns.c
+++ b/usr.sbin/smtpd/dns.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dns.c,v 1.2 2008/11/05 12:14:45 sobrado Exp $ */
+/* $OpenBSD: dns.c,v 1.3 2008/11/10 03:54:08 tedu Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -47,7 +47,6 @@ static void mxsort(struct mxrecord *, size_t);
size_t getmxbyname(char *, char ***);
-/* bubble sort MX records by priority */
static void
mxsort(struct mxrecord *array, size_t len)
{
@@ -55,14 +54,13 @@ mxsort(struct mxrecord *array, size_t len)
u_int32_t j;
struct mxrecord store;
- for (i = j = 0; i < len - 1; ++i) {
- for (j = i + 1; j < len; ++j) {
- if (array[i].priority > array[j].priority) {
- store = array[i];
- array[i] = array[j];
- array[j] = store;
- }
+ for (i = 1; i < len; i++) {
+ store = array[i];
+ for (j = i - 1; j >= 0 && array[j].priority > store.priority;
+ j--) {
+ array[j + 1] = array[j];
}
+ array[j + 1] = store;
}
}
@@ -167,7 +165,7 @@ getmxbyname(char *name, char ***result)
mxnb = sizeof(mxarray) / sizeof(struct mxrecord);
/* Rearrange MX records by priority */
- mxsort((struct mxrecord *)&mxarray, mxnb);
+ mxsort(mxarray, mxnb);
chunklen = 0;
for (i = 0; i < mxnb; ++i)