diff --git a/src/Client/Menus.c b/src/Client/Menus.c index 8015c6e01..1f782abe6 100644 --- a/src/Client/Menus.c +++ b/src/Client/Menus.c @@ -388,12 +388,12 @@ void ListScreen_QuickSort(Int32 left, Int32 right) { UInt32* keys = buffer->FlagsBuffer; UInt32 key; while (left < right) { Int32 i = left, j = right; - Int32 pivot = (i + j) / 2; + String strI, strJ, pivot = StringsBuffer_UNSAFE_Get(buffer, (i + j) / 2); /* partition the list */ while (i <= j) { - while (StringsBuffer_Compare(buffer, pivot, i) > 0) i++; - while (StringsBuffer_Compare(buffer, pivot, j) < 0) j--; + while ((strI = StringsBuffer_UNSAFE_Get(buffer, i), String_Compare(&pivot, &strI)) > 0) i++; + while ((strJ = StringsBuffer_UNSAFE_Get(buffer, j), String_Compare(&pivot, &strJ)) < 0) j--; QuickSort_Swap_Maybe(); } /* recurse into the smaller subset */ diff --git a/src/Client/String.c b/src/Client/String.c index bdcf25284..50f4fe7f2 100644 --- a/src/Client/String.c +++ b/src/Client/String.c @@ -411,13 +411,15 @@ Int32 String_Compare(STRING_PURE String* a, STRING_PURE String* b) { Int32 i; for (i = 0; i < minLen; i++) { - if (a->buffer[i] == b->buffer[i]) continue; - return a->buffer[i] > b->buffer[i] ? 1 : -1; + UInt8 aCur = a->buffer[i]; Char_MakeLower(aCur); + UInt8 bCur = b->buffer[i]; Char_MakeLower(bCur); + + if (aCur == bCur) continue; + return (Int32)aCur - (Int32)bCur; } /* all chars are equal here - same string, or a substring */ - if (a->length == b->length) return 0; - return a->length > b->length ? 1 : -1; + return a->length - b->length; } void String_Format1(STRING_TRANSIENT String* str, const UInt8* format, const void* a1) { @@ -781,12 +783,6 @@ void StringsBuffer_Remove(StringsBuffer* buffer, UInt32 index) { buffer->UsedElems -= len; } -Int32 StringsBuffer_Compare(StringsBuffer* buffer, UInt32 idxA, UInt32 idxB) { - String strA = StringsBuffer_UNSAFE_Get(buffer, idxA); - String strB = StringsBuffer_UNSAFE_Get(buffer, idxB); - return String_Compare(&strA, &strB); -} - bool WordWrap_IsWrapper(UInt8 c) { return c == NULL || c == ' ' || c == '-' || c == '>' || c == '<' || c == '/' || c == '\\';