Skip to content

Commit

Permalink
Make two-argument Remove faster.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fingolfin committed Jan 2, 2023
1 parent bc29a47 commit 3c5466c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/list.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3c5466c

Please sign in to comment.