summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-03-11 00:55:39 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-03-11 00:55:39 (GMT)
commit1bacbd3042bc6fa665f6c35a34c738d4782c9f91 (patch)
treef7ab20e0eb37cea06615ee8b2b720fcf616dcc95
parent87798a1fba0d80e4ae002785dd5fda2b02c82d50 (diff)
downloadpbn-1bacbd3042bc6fa665f6c35a34c738d4782c9f91.zip
pbn-1bacbd3042bc6fa665f6c35a34c738d4782c9f91.tar.gz
pbn-1bacbd3042bc6fa665f6c35a34c738d4782c9f91.tar.bz2
pbn-1bacbd3042bc6fa665f6c35a34c738d4782c9f91.tar.xz
pbn_cmp: optimize comparison
Make the loop a bit cleaner by simply comparing for equality first.
-rw-r--r--pbn_cmp.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/pbn_cmp.c b/pbn_cmp.c
index d8fadf1..45039b9 100644
--- a/pbn_cmp.c
+++ b/pbn_cmp.c
@@ -32,10 +32,8 @@ int pbn_cmp(const struct pbn *s1, const struct pbn *s2)
i = (s1->bits+PBN_ATOM_BITS-1)/PBN_ATOM_BITS;
while (i >= 0) {
- if (s1->num[i] > s2->num[i])
- return gt;
- else if (s1->num[i] < s2->num[i])
- return lt;
+ if (s1->num[i] != s2->num[i])
+ return (s1->num[i] < s2->num[i]) ? lt : gt;
i--;
}
@@ -54,10 +52,8 @@ int pbn_abscmp(const struct pbn *s1, const struct pbn *s2)
i = (s1->bits+PBN_ATOM_BITS-1)/PBN_ATOM_BITS;
while (i >= 0) {
- if (s1->num[i] > s2->num[i])
- return 1;
- else if (s1->num[i] < s2->num[i])
- return -1;
+ if (s1->num[i] != s2->num[i])
+ return (s1->num[i] < s2->num[i]) ? -1 : 1;
i--;
}