Browse Source

Fix sort.compare_strings for prefixes

Atanas Dimitrov 3 years ago
parent
commit
4cb489b9e4
1 changed files with 6 additions and 1 deletions
  1. 6 1
      core/sort/sort.odin

+ 6 - 1
core/sort/sort.odin

@@ -684,5 +684,10 @@ compare_f64s :: proc(a, b: f64) -> int {
 compare_strings :: proc(a, b: string) -> int {
 compare_strings :: proc(a, b: string) -> int {
 	x := transmute(mem.Raw_String)a
 	x := transmute(mem.Raw_String)a
 	y := transmute(mem.Raw_String)b
 	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
 }
 }