Logged In: YES user_id=7887 Raymond, have you done any performance tests showing that the proposed scheme is better? I've created a small test bed for the two patterns here and it looks like the current pattern is faster for small sets. Given the fact that this is a recursive pattern, and that I'm unsure about the kind of patterns which are most used, I'm a little bit uncomfortable in applying this.
Logged In: YES user_id=80475 It needs to be timed on very large patterns -- it will always do worse on very small patterns (due to the time to setup the dispatch table). I'm not satisfied with the patch the way it stands. Ideally, the dispatch table needs to be pre-computed at compile time. The trick is how to view the enclosing variables (passing them as arguments is slow; using globals is not especially clean or fast). If that were resolved, then this approach would just about always be faster (a dictioary lookup and function call versus a long chain of elifs). Any suggestions are welcome.
Logged In: YES user_id=80475 I can't see any way to fix the long if/elif chain without introducing switch/case. The dispatch idiom is too expensive in terms of function call overhead and data sharing costs.