Optimization for self-matching of match_first