From d38939c7e8ca67a3991949cb17bf052b840d1aa4 Mon Sep 17 00:00:00 2001 From: Michael Neumann Date: Fri, 25 Jan 2013 05:26:51 -0600 Subject: [PATCH] Slightly optimize read_line() No need to allocate an additional vector. Instead directly push into the string. --- src/libcore/io.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcore/io.rs b/src/libcore/io.rs index fedcb951196..37e8784b68d 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -185,13 +185,13 @@ impl 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] {