mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
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 {
|
||||
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] {
|
||||
|
Loading…
Reference in New Issue
Block a user