From 2cbffab5a398f7f4a21b88fc457b845f0d01fc89 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Tue, 17 Jan 2023 00:01:57 +0100 Subject: [PATCH] code comparison optimization --- code.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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; } -- 2.30.2