... a regsubex looks ludicrous in terms of ...performance
Actually, I don't see how $regsubex would be much less performant than the solution suggested. What's wrong with regular expressions? I believe what he currently has there "looks ludicruous in terms of readability, script size and performance".
... which might well increase performance..
versus what? something like this, which probably "looks ludicruous in terms of ...performance"?
on 1:START: {
var %x = 1
while ($gettok($chanmodes,%x,44) != $null) {
var %y = 1
while ($mid($v1,%y,1) != $null) {
hadd -m $server $v1 %x
inc %y
}
inc %x
}
}
alias parsemodes {
var %x = 1, %sign
bset -t &chanmodes 1 $1
tokenize 32 $2-
while ($bvar(&chanmodes,%x).text != $null) {
var %c = $v1, %num = $hget($server,$v1)
if (!%num) { %sign = %c }
else {
if (%num isnum 1-2 || (%num == 3 && %sign = +)) {
echo -a $+(%sign,%c) $1
tokenize 32 $2-
}
else { echo -a $+(%sign,%c) }
}
inc %x
}
bunset &chanmodes
}
He is using $findtok for the very end of finding not the token itslf, but its position in the string.
I don't quite think $poscs would work for his case.
There's nothing wrong with his suggestion. I just would hate to see it jeopardise (even slightly) the performance of $matchtok/$findtok/whatever in scenarios where one could not use something similar to the above example. But then again, can't expect newb scripters to want to expand their horizons past elementary algorithms using language constructs and into algorithms using objects.