From b9b64c35173b82d01dfc0c115744df9d613171a3 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 29 Dec 2022 02:37:59 +0100 Subject: [PATCH] Make two-argument Remove faster. Before: gap> l := List([1..100000], i->[i]);; gap> while Length(l)>0 do Remove(l,Length(l)); od; time; 53937 After: gap> l := List([1..100000], i->[i]);; gap> while Length(l)>0 do Remove(l,Length(l)); od; time; 17 --- lib/list.gi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/list.gi b/lib/list.gi index 0adbd7345f..eb83455a0d 100644 --- a/lib/list.gi +++ b/lib/list.gi @@ -1984,9 +1984,12 @@ InstallMethod(Remove, "one argument", [IsList and IsMutable], return x; end); -InstallMethod(Remove, "two arguments, fast", [IsList and IsPlistRep and IsMutable, IsPosInt], +InstallEarlyMethod(Remove, function(l,p) local ret,x,len; + if not (IsPlistRep(l) and IsMutable(l) and IsPosInt(p)) then + TryNextMethod(); + fi; len := Length(l); ret := IsBound(l[p]); if ret then