Skip to content

Commit

Permalink
Reuse read_string() in read_name() (#23)
Browse files Browse the repository at this point in the history
Deduplicate identical functionality: `read_string()` simply "extends"
`read_name()` by first reading the string length.  All existing uses of
`read_string()` parse the length elsewhere, or use the length for
multiple purposes (typically a type-switch).
  • Loading branch information
MarijnS95 authored Apr 3, 2023
1 parent 49aa4c4 commit 2ce20cf
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ fn read_string<R: Read + Seek>(reader: &mut R, len: usize) -> Result<String, Par

fn read_name<R: Read + Seek>(reader: &mut R) -> Result<String, ParseError> {
let len = reader.read_u32::<LittleEndian>()? as usize;
let mut string = String::with_capacity(len);
for _ in 0..len {
let c = reader.read_u8()? as char;
string.push(c);
}
Ok(string)
read_string(reader, len)
}

fn read_d_vec3<R: Read + Seek>(reader: &mut R) -> Result<glam::DVec3, ParseError> {
Expand Down

0 comments on commit 2ce20cf

Please sign in to comment.