From: Markus Triska Date: Sun, 20 Aug 2023 19:38:33 +0000 (+0200) Subject: remove optional (+)/1 prefix in get_atts/2 and put_atts/2 calls X-Git-Tag: v0.9.2~4^2~1 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=24456e9703f1d23b4b75985e0a11608e18adaa29;p=scryer-prolog.git remove optional (+)/1 prefix in get_atts/2 and put_atts/2 calls The (+)/1 prefix in get_atts/2 at line 4219 by itself already causes a greater than 15% slowdown for the benchmark shown in #1730: ?- N #= 2^14, time(((between(1, N, _), X #\= Y, false) ; true)). The performance impact is not a good reason to remove the optional (+)/1 prefix! Performance issues should be addressed at the root, in this case get_atts/2 (#1962). We should never manually work around performance issues in built-in predicates. In contrast, readability is a good argument, and I find the calls slightly easier to read without the optional (+)/1 prefix. The prefix is now consistently omitted when possible. --- diff --git a/src/lib/clpz.pl b/src/lib/clpz.pl index a6655687..fbb78554 100644 --- a/src/lib/clpz.pl +++ b/src/lib/clpz.pl @@ -3967,7 +3967,7 @@ insert_queue(Element, Which) --> Tail0 = [Element|Tail] ; Head = [Element|Tail] ), - put_atts(Arg, +queue(Head,Tail)) }. + put_atts(Arg, queue(Head,Tail)) }. domain_spread(Dom, Spread) :- @@ -4199,9 +4199,9 @@ ignore(Goal) :- ( Goal -> true ; true ). print_queue --> state(queue(Goal,Fast,Slow,_)), - { ignore(get_atts(Goal, +queue(GHs,_))), - ignore(get_atts(Fast, +queue(FHs,_))), - ignore(get_atts(Slow, +queue(SHs,_))), + { ignore(get_atts(Goal, queue(GHs,_))), + ignore(get_atts(Fast, queue(FHs,_))), + ignore(get_atts(Slow, queue(SHs,_))), format("Current queue:~n goal: ~q~n fast: ~q~n slow: ~q~n~n", [GHs,FHs,SHs]) }. @@ -4216,14 +4216,14 @@ queue_get_arg(Which, Element) --> queue_get_arg_(Queue, Which, Element) :- arg(Which, Queue, Arg), - get_atts(Arg, +queue([Element|Elements],Tail)), + get_atts(Arg, queue([Element|Elements],Tail)), ( var(Elements) -> put_atts(Arg, -queue(_,_)) - ; put_atts(Arg, +queue(Elements,Tail)) + ; put_atts(Arg, queue(Elements,Tail)) ). queue_enabled --> state(queue(_,_,_,Aux)), { \+ get_atts(Aux, disabled) }. -disable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, +disabled) }. +disable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, disabled) }. enable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, -disabled) }. portray_propagator(propagator(P,_), F) :- functor(P, F, _).