From f58d4e6bb0e8041f4c5aad8a47e405f0362e826d Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 17 May 2025 10:22:27 -0400 Subject: [PATCH] Make indice reading (for models) slightly faster As suspected - this was a little slow, and can be corroborated with Hotspot. This is only a marginal increase in performance, it isn't huge but still worth doing. --- src/model/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/model/mod.rs b/src/model/mod.rs index 3bb1b57..b97a4e5 100755 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -10,8 +10,8 @@ pub mod vertex_declarations; use std::io::{Cursor, Seek, SeekFrom}; use std::mem::size_of; -use binrw::BinRead; use binrw::BinReaderExt; +use binrw::{BinRead, VecArgs}; use binrw::{BinWrite, BinWriterExt, binrw}; use crate::common_file_operations::{read_bool_from, write_bool_as}; @@ -694,12 +694,10 @@ impl MDL { )) .ok()?; - // TODO: optimize! - let mut indices: Vec = - Vec::with_capacity(model.meshes[j as usize].index_count as usize); - for _ in 0..model.meshes[j as usize].index_count { - indices.push(cursor.read_le::().ok()?); - } + let index_count = model.meshes[j as usize].index_count as usize; + let indices: Vec = cursor + .read_le_args(VecArgs::builder().count(index_count).finalize()) + .ok()?; let mut submeshes: Vec = Vec::with_capacity(model.meshes[j as usize].submesh_count as usize);