From e979209de3fe6ca0c54dbe1e95f74af22f5c7f5c Mon Sep 17 00:00:00 2001 From: nova Date: Fri, 3 Oct 2025 16:53:18 +0200 Subject: [PATCH] slight likely branch improvements --- sorting.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/sorting.c b/sorting.c index 9399d20..cb7141e 100644 --- a/sorting.c +++ b/sorting.c @@ -43,38 +43,37 @@ int sort_natural(const void *file0, const void *file1){ char result = 0; do { - is_num = 0; - if ((*a >= '0') && (*a <= '9')) { + if ((*a <= '9') && (*a >= '0')) { parsed_number0 = 0; - while((*a >= '0') && (*a <= '9')) { + do { parsed_number0 = (parsed_number0 * 10) + (*a - '0'); a++; - } + } while((*a <= '9') && (*a >= '0')); is_num |= 1; } - if ((*b >= '0') && (*b <= '9')) { + if ((*b <= '9') && (*b >= '0')) { parsed_number1 = 0; - while((*b >= '0') && (*b <= '9')) { + do { parsed_number1 = (parsed_number1 * 10) + (*b - '0'); b++; - } + } while((*b <= '9') && (*b >= '0')); is_num |= 2; } if (is_num) { if (is_num == 1) { - if (*b < '0') { - result = 1; - } else { + if (*b > '9') { result = -1; + } else { + result = 1; } break; } else if (is_num == 2) { - if (*a < '0') { - result = -1; - } else { + if (*a > '9') { result = 1; + } else { + result = -1; } break; } else { @@ -88,6 +87,7 @@ int sort_natural(const void *file0, const void *file1){ } /* those breaks are not set here, due to the possibillity that both numbers are equal * in which case the comparison should continue */ + is_num = 0; } unsigned char aa = ((*a >= 'A') && (*a <= 'Z')) ? (*a | ' ') : *a;