From 1d2ab651cf64b44d0ba68fc500fee0500f9487e4 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Sat, 30 Oct 2010 02:22:03 +0300 Subject: [PATCH 2/2] Cleanup: Simplify comparisons (a - b > 0) to (a > b) etc This change was done using Coccinelle using the following spatch: virtual org,diff @@ expression a, b; @@ ( - a - b > 0 + a > b | - a - b >= 0 + a >= b | - a - b < 0 + a < b | - a - b <= 0 + a <= b ) Marti Raudsepp --- contrib/pgcrypto/pgp-decrypt.c | 2 +- src/backend/postmaster/bgwriter.c | 2 +- src/backend/utils/adt/formatting.c | 2 +- src/backend/utils/adt/varlena.c | 2 +- src/bin/scripts/createlang.c | 6 +++--- src/bin/scripts/droplang.c | 6 +++--- src/test/examples/testlo.c | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/contrib/pgcrypto/pgp-decrypt.c b/contrib/pgcrypto/pgp-decrypt.c index c9aa6cd..ffd3287 100644 --- a/contrib/pgcrypto/pgp-decrypt.c +++ b/contrib/pgcrypto/pgp-decrypt.c @@ -747,7 +747,7 @@ copy_crlf(MBuf *dst, uint8 *data, int len, int *got_cr) p = tmpbuf; } } - if (p - tmpbuf > 0) + if (p > tmpbuf) { res = mbuf_append(dst, tmpbuf, p - tmpbuf); if (res < 0) diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index 0690ab5..c4232c7 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -1032,7 +1032,7 @@ RequestCheckpoint(int flags) new_failed = bgs->ckpt_failed; SpinLockRelease(&bgs->ckpt_lck); - if (new_done - new_started >= 0) + if (new_done >= new_started) break; CHECK_FOR_INTERRUPTS(); diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index fc0bf43..3b40164 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -4228,7 +4228,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, if (IS_DECIMAL(Np->Num)) Np->last_relevant = get_last_relevant_decnum( Np->number + - ((Np->Num->zero_end - Np->num_pre > 0) ? + ((Np->Num->zero_end > Np->num_pre) ? Np->Num->zero_end - Np->num_pre : 0)); } diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 363fd3c..2d9f3a3 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -2805,7 +2805,7 @@ replace_text_regexp(text *src_text, void *regexp, * Copy the text to the left of the match position. Note we are given * character not byte indexes. */ - if (pmatch[0].rm_so - data_pos > 0) + if (pmatch[0].rm_so > data_pos) { int chunk_len; diff --git a/src/bin/scripts/createlang.c b/src/bin/scripts/createlang.c index 23ce45b..d1d94ce 100644 --- a/src/bin/scripts/createlang.c +++ b/src/bin/scripts/createlang.c @@ -91,19 +91,19 @@ main(int argc, char *argv[]) } } - if (argc - optind > 0) + if (argc > optind) { if (listlangs) dbname = argv[optind++]; else { langname = argv[optind++]; - if (argc - optind > 0) + if (argc > optind) dbname = argv[optind++]; } } - if (argc - optind > 0) + if (argc > optind) { fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind]); diff --git a/src/bin/scripts/droplang.c b/src/bin/scripts/droplang.c index 2ba0728..01c0134 100644 --- a/src/bin/scripts/droplang.c +++ b/src/bin/scripts/droplang.c @@ -102,19 +102,19 @@ main(int argc, char *argv[]) } } - if (argc - optind > 0) + if (argc > optind) { if (listlangs) dbname = argv[optind++]; else { langname = argv[optind++]; - if (argc - optind > 0) + if (argc > optind) dbname = argv[optind++]; } } - if (argc - optind > 0) + if (argc > optind) { fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind]); diff --git a/src/test/examples/testlo.c b/src/test/examples/testlo.c index 205bed7..405982a 100644 --- a/src/test/examples/testlo.c +++ b/src/test/examples/testlo.c @@ -90,7 +90,7 @@ pickout(PGconn *conn, Oid lobjId, int start, int len) buf = malloc(len + 1); nread = 0; - while (len - nread > 0) + while (len > nread) { nbytes = lo_read(conn, lobj_fd, buf, len - nread); buf[nbytes] = '\0'; @@ -125,7 +125,7 @@ overwrite(PGconn *conn, Oid lobjId, int start, int len) buf[i] = '\0'; nwritten = 0; - while (len - nwritten > 0) + while (len > nwritten) { nbytes = lo_write(conn, lobj_fd, buf + nwritten, len - nwritten); nwritten += nbytes; -- 1.7.3.2