File 1720-Fix-stability-in-keysort-2.patch of Package erlang

From 72ccec3c04f6bf8c5dbaab0bbd269f94ce697085 Mon Sep 17 00:00:00 2001
From: Raimo Niskanen <raimo@erlang.org>
Date: Tue, 10 Jun 2025 10:13:00 +0200
Subject: [PATCH 4/5] Fix stability in keysort/2

The optimization of leading equal elements was broken in two ways:

It used full term comparison as an optimization assuming that it
would be faster than looking at the elements, which could be
plain wrong if keysort is used for large tuples that are expensive
to compare but with small keys.

When transitioning to descending split in that the collected
element order had to be reversed, and the run of equal elements
had to be closed to ensure they all end up before the
descending sort elements.
---
 lib/stdlib/src/lists.erl | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/stdlib/src/lists.erl b/lib/stdlib/src/lists.erl
index cb1c008ed1..9e35f2f547 100644
--- a/lib/stdlib/src/lists.erl
+++ b/lib/stdlib/src/lists.erl
@@ -987,14 +987,14 @@ keysort(I, L) when is_integer(I), I > 0 ->
 	    end
     end.
 
-keysort_1(I, X, EX, [Y | L], R) when X == Y ->
-    keysort_1(I, Y, EX, L, [X | R]);
 keysort_1(I, X, EX, [Y | L], R) ->
     case element(I, Y) of
-	EY when EX =< EY ->
+	EY when EX < EY ->
 	    keysplit_1(I, X, EX, Y, EY, L, R, []);
-	EY ->
-	    keysplit_2(I, X, EX, Y, EY, L, R, [])
+	EY when EX > EY ->
+	    keysplit_2(I, X, EX, Y, EY, L, [], [lists:reverse(R)]);
+        EY -> % EX == EY
+            keysort_1(I, Y, EY, L, [X | R])
     end;
 keysort_1(_I, X, _EX, [], R) ->
     lists:reverse(R, [X]).
-- 
2.43.0

openSUSE Build Service is sponsored by