I apologise for misconstruing the efficiency of the expression as I posted it. I also apologise since, it seems from a little bit of further research, that mIRC's handling of inline if statements is grossly less efficient than I'd thought. In any other language, interpreted or not, they're handled with a rather great deal more speed than mIRC.
I was taught that regardless of the implementation of the regular expression, using a regular expression with no regards to the specific content of the text - that is, if the regular expression needs to be invoked at all - should be frowned upon in favour of simpler if statements to check if the complexity of a regular expression is required. Unfortunately, when it comes to mIRC, this method of thinking is less efficient than desired, but presuming the average percentage of lines containing 'BBCode' is under 90%, there's still advantage to be gained with the use of an if statement. Execution speed when only 5% of lines contain 'BBCode' is nearly halved, while when 95% of lines contain 'BBCode' execution speed is slower by 10%. (For reference, the percentage at which the two methods apparently reach equal execution times is 89.7%, although I doubt that the method of testing we're using is accurate to that level of precision.)
And, in case you're curious, the adaption to your speedcheck alias which I used to test this out is:
alias speedcheck {
;Play with average percentage of lines containing []s
var %perc 897
;var %perc 500
var %b = 20000
!var %t = $ticks
while (%b) {
var %a = $iif($r(1,1000) > %perc,$str(abcd,100),$str(aaa[ $str(b,30) ]ccc,10))
if ([ isin %a) { !noop $regsubex(%a,/\[[^]]+\]/g,) }
else { !noop %a }
!dec %b
}
!var %c = $ticks - %t
var %b = 20000
!var %t = $ticks
while (%b) {
var %a = $iif($r(1,1000) > %perc,$str(abcd,100),$str(aaa[ $str(b,30) ]ccc,10))
!noop $regsubex(%a,/\[[^]]+\]/g,)
!dec %b
}
!var %d = $ticks - %t
echo -a First method: %c ms -- Second method: %d ms
}
Anyway, Jaytea, thankyou for giving me the opportunity to learn a little more.
You're missing the point. Using a character class - especially a negated one - creates additional work for the regular expression engine. The simpler the match, the quicker the function. A character class is slower than a wildcard match; The . wildcard is particularly efficient, since the regular expression engine doesn't have to care so much about what it matches.
The byte-size of your regular expression has very little to do with its efficiency.
Strictly speaking, if you wanted to improve the execution speed when dealing with large amounts of text, you'd use something along the lines of
alias a4 return $iif([ isin $1-,$regsubex($1,/[.+?]/g,),$1-)
Since an if/find operation is vastly quicker in execution than a regular expression.
Hope my explanation helps.
Your regular expression is long and requires an unnecessary amount of parsing. /[.+?]/g is slightly more efficient.
Sigh. Even if you add a ",0" to my $iif() statement, it still won't behave like the original, since the lower bound would be 0 rather than 1. Realistically, you'd need to use $calc() to increase the output by 1, in order to match his example.
HOWEVER the fact that it does not match the example in behaviour by returning the same values for the same modes is irrelevant - the fact remains that higher modes return higher numbers, thus you're able to establish precedence, which is the point of the snippet as explained in the original post.
I hate to break it to you, but if you're storing that much data in an INI file, perhaps the access is frequent enough to warrant the use of a set of hash-tables.
Besides that grudge, there are two areas in which this could be improved greatly:
1) Obfuscation of variable names makes life difficult. %y, %x, %d, and %b could be a little more descriptive.
2) If I were you, I'd have written it using /fopen, /fseek, and /fwrite. Much faster and more powerful.
Other than that, it looks useful and well written. :]