Optimize merge_sym_transitions and merge_char_transitions