Quote:
Originally Posted by ownedbycats
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.