Skip to content

Commit d38939c

Browse files
mneumannbrson
authored andcommitted
Slightly optimize read_line()
No need to allocate an additional vector. Instead directly push into the string.
1 parent 1ecdf3a commit d38939c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/libcore/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ impl<T: Reader> T : ReaderUtil {
185185
}
186186

187187
fn read_line(&self) -> ~str {
188-
let mut bytes = ~[];
188+
let mut line = ~"";
189189
loop {
190190
let ch = self.read_byte();
191191
if ch == -1 || ch == 10 { break; }
192-
bytes.push(ch as u8);
192+
str::push_char(&mut line, ch as char);
193193
}
194-
str::from_bytes(bytes)
194+
line
195195
}
196196

197197
fn read_chars(&self, n: uint) -> ~[char] {

0 commit comments

Comments
 (0)