File 1005-erl_lint-Eliminate-bottleneck-when-there-are-many-cl.patch of Package erlang

From d442a51b6126ec0e774af2a6313b9c96efcec8ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Wed, 1 Oct 2025 06:39:25 +0200
Subject: [PATCH 1/2] erl_lint: Eliminate bottleneck when there are many
 clauses

When a `case` had an extreme number of clauses, say hundred thousands
or more, `erl_lint` could spending minutes instead of part of a second
checking the code.

The reason was a function with quadratic complexity caused by
using `lists:partition/1` when `lists:splitwhile/1` would work.
---
 lib/stdlib/src/erl_lint.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl
index 091faea654..fcbff047af 100644
--- a/lib/stdlib/src/erl_lint.erl
+++ b/lib/stdlib/src/erl_lint.erl
@@ -3988,7 +3988,7 @@ icrt_export([{V,{{export,_},_,_}}|Vs0], [{V,{{export,_}=S0,_,As}}|Vt],
     %% V was an exported variable and has been used in an expression in at least
     %% one clause. Its state needs to be merged from all clauses to silence any
     %% exported var warning already emitted.
-    {VVs,Vs} = lists:partition(fun ({K,_}) -> K =:= V end, Vs0),
+    {VVs,Vs} = lists:splitwith(fun ({K,_}) -> K =:= V end, Vs0),
     S = foldl(fun ({_,{S1,_,_}}, AccS) -> merge_state(AccS, S1) end, S0, VVs),
     icrt_export(Vs, Vt, In, I, [{V,{S,used,As}}|Acc]);
 icrt_export([{V,_}|Vs0], [{V,{_,_,As}}|Vt], In, I, Acc) ->
@@ -4003,7 +4003,7 @@ icrt_export([{V1,_}|_]=Vs, [{V2,_}|Vt], In, I, Acc) when V1 > V2 ->
     icrt_export(Vs, Vt, In, I, Acc);
 icrt_export([{V,_}|_]=Vs0, Vt, In, I, Acc) ->
     %% V is a new variable.
-    {VVs,Vs} = lists:partition(fun ({K,_}) -> K =:= V end, Vs0),
+    {VVs,Vs} = lists:splitwith(fun ({K,_}) -> K =:= V end, Vs0),
     F = fun ({_,{S,U,As}}, {AccI,AccS0,AccAs0}) ->
                 AccS = case {S,AccS0} of
                            {{unsafe,_},{unsafe,_}} ->
-- 
2.51.0

openSUSE Build Service is sponsored by