View Single Post
Old 07-07-2021, 06:14 AM   #138
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I might've asked this before, but does it do all the checks, or only continue the check when it passes the other ones?
Logical conditional expressions do "shortcutting", which means that they stop as soon as they know the answer. In practice, for "a && b" it will stop if a is false, returning ''. For "a || b" it will stop if a is true, returning '1'.
Quote:
If the latter, since #currentlyreading is another composite (psuedobool, it returns 'true' if it passes certain checks), would putting it last be better practice for performance?
Probably. It depends on the complexity of the other parts of the &&. In this template, almost certainly.

In general, for a sequence of && clauses put them in the order you expect them to most often fail. For a sequence of || clauses put them in the order you expect them to most often succeed.
Quote:
Also, are there any other improvements that can be made to this?
Given that the variable 'a' is used in only one place, it is best to remove the assignment and change the line
Code:
strcat(format_number(subtract(a, 1), '{0:,d}'), '/',ccount)
to be
Code:
strcat(format_number(re(input, '.*\/file(\d+).*', '\1') - 1, '{0:,d}'), '/',ccount)
The expression "a - 1" is faster than the expression "subtract(a, 1)" because it avoids the function call.

Last edited by chaley; 07-07-2021 at 12:35 PM. Reason: Fix shortcutting
chaley is offline   Reply With Quote