@@ -12,7 +12,7 @@ pub(crate) struct OutFile {
12
12
}
13
13
14
14
pub struct Content {
15
- bytes : Vec < u8 > ,
15
+ bytes : String ,
16
16
section_pending : bool ,
17
17
blocks_pending : Vec < & ' static str > ,
18
18
}
@@ -42,9 +42,9 @@ impl OutFile {
42
42
pub fn end_block ( & mut self , block : & ' static str ) {
43
43
let content = self . content . get_mut ( ) ;
44
44
if content. blocks_pending . pop ( ) . is_none ( ) {
45
- content. bytes . extend_from_slice ( b "} // ") ;
46
- content. bytes . extend_from_slice ( block. as_bytes ( ) ) ;
47
- content. bytes . push ( b '\n') ;
45
+ content. bytes . push_str ( "} // " ) ;
46
+ content. bytes . push_str ( block) ;
47
+ content. bytes . push ( '\n' ) ;
48
48
content. section_pending = true ;
49
49
}
50
50
}
@@ -58,19 +58,19 @@ impl OutFile {
58
58
let front = & self . front . bytes ;
59
59
let content = & self . content . borrow ( ) . bytes ;
60
60
let len = front. len ( ) + !front. is_empty ( ) as usize + content. len ( ) ;
61
- let mut out = Vec :: with_capacity ( len) ;
62
- out. extend_from_slice ( front) ;
61
+ let mut out = String :: with_capacity ( len) ;
62
+ out. push_str ( front) ;
63
63
if !front. is_empty ( ) {
64
- out. push ( b '\n') ;
64
+ out. push ( '\n' ) ;
65
65
}
66
- out. extend_from_slice ( content) ;
67
- out
66
+ out. push_str ( content) ;
67
+ out. into_bytes ( )
68
68
}
69
69
}
70
70
71
71
impl Write for Content {
72
72
fn write_str ( & mut self , s : & str ) -> fmt:: Result {
73
- self . write_bytes ( s . as_bytes ( ) ) ;
73
+ self . write ( s ) ;
74
74
Ok ( ( ) )
75
75
}
76
76
}
@@ -82,30 +82,30 @@ impl Content {
82
82
83
83
fn new ( ) -> Self {
84
84
Content {
85
- bytes : Vec :: new ( ) ,
85
+ bytes : String :: new ( ) ,
86
86
section_pending : false ,
87
87
blocks_pending : Vec :: new ( ) ,
88
88
}
89
89
}
90
90
91
- fn write_bytes ( & mut self , b : & [ u8 ] ) {
91
+ fn write ( & mut self , b : & str ) {
92
92
if !b. is_empty ( ) {
93
93
if !self . blocks_pending . is_empty ( ) {
94
94
if !self . bytes . is_empty ( ) {
95
- self . bytes . push ( b '\n') ;
95
+ self . bytes . push ( '\n' ) ;
96
96
}
97
97
for block in self . blocks_pending . drain ( ..) {
98
- self . bytes . extend_from_slice ( block. as_bytes ( ) ) ;
99
- self . bytes . extend_from_slice ( b " {\n ") ;
98
+ self . bytes . push_str ( block) ;
99
+ self . bytes . push_str ( " {\n " ) ;
100
100
}
101
101
self . section_pending = false ;
102
102
} else if self . section_pending {
103
103
if !self . bytes . is_empty ( ) {
104
- self . bytes . push ( b '\n') ;
104
+ self . bytes . push ( '\n' ) ;
105
105
}
106
106
self . section_pending = false ;
107
107
}
108
- self . bytes . extend_from_slice ( b) ;
108
+ self . bytes . push_str ( b) ;
109
109
}
110
110
}
111
111
}
0 commit comments