optimize remove_patterns for mutable strings