From 4cb489b9e43e6934f69886db3a10bce9d3524970 Mon Sep 17 00:00:00 2001 From: Atanas Dimitrov Date: Wed, 3 Aug 2022 16:22:54 +0300 Subject: [PATCH] Fix sort.compare_strings for prefixes --- core/sort/sort.odin | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/sort/sort.odin b/core/sort/sort.odin index 2ce74294d..a2b4d7ea0 100644 --- a/core/sort/sort.odin +++ b/core/sort/sort.odin @@ -684,5 +684,10 @@ compare_f64s :: proc(a, b: f64) -> int { compare_strings :: proc(a, b: string) -> int { x := transmute(mem.Raw_String)a y := transmute(mem.Raw_String)b - return mem.compare_byte_ptrs(x.data, y.data, min(x.len, y.len)) + + ret := mem.compare_byte_ptrs(x.data, y.data, min(x.len, y.len)) + if ret == 0 && x.len != y.len { + return -1 if x.len < y.len else +1 + } + return ret }