changeset 669:1bb8b34dbd32

Don’t allocate a Vec while reading a String in ECL.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 12 Aug 2019 15:10:19 +0200
parents 140ee7de6d90
children cdb484115c5b
files src/th06/ecl.rs
diffstat 1 files changed, 1 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/th06/ecl.rs	Mon Aug 12 15:09:53 2019 +0200
+++ b/src/th06/ecl.rs	Mon Aug 12 15:10:19 2019 +0200
@@ -135,7 +135,7 @@
 /// Parse a SHIFT_JIS byte string of length 34 into a String.
 pub fn le_String(i: &[u8]) -> IResult<&[u8], String> {
     assert_eq!(i.len(), 34);
-    let data = i.splitn(2, |c| *c == b'\0').collect::<Vec<_>>()[0];
+    let data = i.splitn(2, |c| *c == b'\0').nth(0).unwrap();
     let (string, encoding, replaced) = SHIFT_JIS.decode(data);
     Ok((&i[34..], string.into_owned()))
 }