From: Laurent Mazet Date: Mon, 16 Jan 2023 23:01:57 +0000 (+0100) Subject: code comparison optimization X-Git-Url: https://secure.softndesign.org/git/?p=compress.git;a=commitdiff_plain;h=2cbffab5a398f7f4a21b88fc457b845f0d01fc89 code comparison optimization --- diff --git a/code.c b/code.c index 5872443..b8c8e78 100644 --- a/code.c +++ b/code.c @@ -23,14 +23,12 @@ int codcat (char *dst, int n, char *src) int codcmp (char *cod1, char *cod2) { - int i = -1; - - do { - i++; - if (cod1[i] != cod2[i]) { - return (cod1[i] < cod2[i]) ? -1 : 1; + while ((*cod1 != 0) || (*cod2 != 0)) { + int test = *cod1++ - *cod2++; + if (test != 0) { + return (test < 0) ? -1 : 1; } - } while (cod1[i] != 0); + } return 0; }