mirror of https://git.sr.ht/~stygianentity/bincode
Merge pull request #13 from bitonic/fast-str-read
Read strings in one go, not byte-by-byte.
This commit is contained in:
commit
ee09eb19da
|
|
@ -71,10 +71,7 @@ impl<'a, R: Reader+Buffer> Decoder for DecoderReader<'a, R> {
|
|||
}
|
||||
fn read_str(&mut self) -> IoResult<String> {
|
||||
let len = try!(self.read_uint());
|
||||
let mut vector = Vec::with_capacity(len as uint);
|
||||
for _ in range(0, len) {
|
||||
vector.push(try!(self.reader.read_u8()));
|
||||
}
|
||||
let vector = try!(self.reader.read_exact(len));
|
||||
Ok(String::from_utf8(vector).unwrap())
|
||||
}
|
||||
fn read_enum<T, F>(&mut self, _: &str, f: F) -> IoResult<T> where
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ fn test_numbers() {
|
|||
fn test_string() {
|
||||
the_same("".to_string());
|
||||
the_same("a".to_string());
|
||||
the_same("ƒoo".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in New Issue