The wiki defines the opcode as
For each signature and public key pair, OP_CHECKSIG is executed. If more public keys than signatures are listed, some key/sig pairs can fail. All signatures need to match a public key. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.
This means that there is a need to check every signature against every public key. This is O(N^2) performance. In a 10 of 10 case, around 50 checks would be required.
In the code it appears to require that the keys and signatures are in the same order.
Assuming a 2 of 3 case, with 3 signatures a, b, c and 3 keys A, B and C,
a, c, A, B, C
would work, since a and c are in the right order.
c, a, A, B, C
would fail, since c and a are in the wrong order.
This is the loop.
The 2 counters isig and ikey are only ever incremented. Each key is only every tested against 1 signature. This means that the operation is O(N) performance rather than O(N^2).
Is this correct?
An additional optimisation could be added by using the extra multisig stack item. In a 2 of 10 situation, all 10 keys might need to be checked. The extra item that is popped off the stack could encode which public keys are used. 0x03 would mean that the last 2 public keys are used. This would reduce the verification load.
In most cases, it is probably not that big a deal.