]> Repositorios git - scryer-prolog.git/commitdiff
ENHANCED: Use '$skip_max_list'/4 for greater efficiency of nth0/3.
authorMarkus Triska <[email protected]>
Sun, 21 Aug 2022 11:51:12 +0000 (13:51 +0200)
committerMark Thom <[email protected]>
Thu, 27 Oct 2022 05:36:07 +0000 (23:36 -0600)
This is now possible due to 4c7e2eb8614da9c04f2286f6116b468017fb442c.

See #1529 for the suggestion by @UWN.

src/lib/lists.pl

index 52f862bb12c691f79f31e7b2ede3d7ac747982bb..7cfffa17736eeeae0cf58b76303c0d080c2cb870 100644 (file)
@@ -247,16 +247,10 @@ nth0(N, Es, E) :-
         can_be(integer, N),
         can_be(list, Es),
         (   integer(N) ->
-            nth0_index(N, Es, E)
+            '$skip_max_list'(N, N, Es, [E|_])
         ;   nth0_search(N, Es, E)
         ).
 
-nth0_index(0, [E|_], E) :- !.
-nth0_index(N, [_|Es], E) :-
-        N > 0,
-        N1 is N - 1,
-        nth0_index(N1, Es, E).
-
 nth0_search(N, Es, E) :-
         nth0_search(0, N, Es, E).