File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,28 +103,30 @@ impl Replacer {
103103 & ' a self ,
104104 content : & ' a [ u8 ] ,
105105 ) -> std:: borrow:: Cow < ' a , [ u8 ] > {
106- let mut content = std:: borrow:: Cow :: Borrowed ( content) ;
107- if self . is_literal {
108- let replace_withs = self . replace_withs . iter ( ) . map ( |r| regex:: bytes:: NoExpand ( r) ) ;
109- self . regexes . iter ( ) . zip ( replace_withs) . for_each ( |( regex, replace_with) | {
110- content = regex. replacen (
111- & content,
112- self . max_replacements ,
113- replace_with,
114- ) ;
115- } ) ;
116- } else {
106+ fn r < ' a > (
107+ content : & ' a [ u8 ] ,
108+ replace : impl Iterator < Item = impl regex:: bytes:: Replacer > ,
109+ patterns : impl Iterator < Item = regex:: bytes:: Regex > ,
110+ max_replacements : usize ,
111+ ) -> std:: borrow:: Cow < ' a , [ u8 ] > {
112+ let mut content = std:: borrow:: Cow :: Borrowed ( content) ;
117113 for ( regex, replace_with) in
118- self . regexes . iter ( ) . zip ( & self . replace_withs )
114+ patterns . zip ( replace )
119115 {
120116 content = regex. replacen (
121117 & content,
122- self . max_replacements ,
118+ max_replacements,
123119 replace_with,
124120 ) ;
125121 }
122+ content
123+ }
124+ if self . is_literal {
125+ let mut rep = self . replace_withs . iter ( ) . map ( |r| regex:: bytes:: NoExpand ( r) ) ;
126+ r ( content, rep, self . regexes . into_iter ( ) , self . max_replacements )
127+ } else {
128+ r ( content, self . replace_withs . into_iter ( ) , self . regexes . into_iter ( ) , self . max_replacements )
126129 }
127- content
128130 }
129131
130132 pub ( crate ) fn replace_preview < ' a > (
You can’t perform that action at this time.
0 commit comments