Optimize Pattern matching.