mirror of https://github.com/rust-lang/rust.git
Slightly optimize read_line()
No need to allocate an additional vector. Instead directly push into the string.
This commit is contained in:
parent
1ecdf3abc1
commit
d38939c7e8
|
@ -185,13 +185,13 @@ impl<T: Reader> T : ReaderUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_line(&self) -> ~str {
|
fn read_line(&self) -> ~str {
|
||||||
let mut bytes = ~[];
|
let mut line = ~"";
|
||||||
loop {
|
loop {
|
||||||
let ch = self.read_byte();
|
let ch = self.read_byte();
|
||||||
if ch == -1 || ch == 10 { break; }
|
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] {
|
fn read_chars(&self, n: uint) -> ~[char] {
|
||||||
|
|
Loading…
Reference in New Issue