Slightly optimize read_line()

No need to allocate an additional vector. Instead directly push into the
string.
This commit is contained in:
Michael Neumann 2013-01-25 05:26:51 -06:00 committed by Brian Anderson
parent 1ecdf3abc1
commit d38939c7e8
1 changed files with 3 additions and 3 deletions

View File

@ -185,13 +185,13 @@ impl<T: Reader> T : ReaderUtil {
}
fn read_line(&self) -> ~str {
let mut bytes = ~[];
let mut line = ~"";
loop {
let ch = self.read_byte();
if ch == -1 || ch == 10 { break; }
bytes.push(ch as u8);
str::push_char(&mut line, ch as char);
}
str::from_bytes(bytes)
line
}
fn read_chars(&self, n: uint) -> ~[char] {