From 125ae3bbd8a7affe3525f69d7f51f9868b6e0ce9 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Tue, 10 Sep 2024 21:04:33 +0900 Subject: [PATCH] =?UTF-8?q?`find=5Findex`=20=E2=86=92=20`find=5Fentry=5Fin?= =?UTF-8?q?dex`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/VOICEVOX/voicevox_core/pull/830#discussion_r1751135133 --- crates/voicevox_core/src/voice_model.rs | 35 ++++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/crates/voicevox_core/src/voice_model.rs b/crates/voicevox_core/src/voice_model.rs index 97aade434..9d66c13a3 100644 --- a/crates/voicevox_core/src/voice_model.rs +++ b/crates/voicevox_core/src/voice_model.rs @@ -90,22 +90,25 @@ impl Inner { .await .map_err(|source| error(LoadModelErrorKind::OpenZipFile, source))?; - let manifest = &async { zip.read_file(zip.find_index(MANIFEST_FILENAME)?).await } - .await - .map_err(|source| { - error( - LoadModelErrorKind::ReadZipEntry { - filename: MANIFEST_FILENAME.to_owned(), - }, - source, - ) - })?; + let manifest = &async { + let idx = zip.find_entry_index(MANIFEST_FILENAME)?; + zip.read_file(idx).await + } + .await + .map_err(|source| { + error( + LoadModelErrorKind::ReadZipEntry { + filename: MANIFEST_FILENAME.to_owned(), + }, + source, + ) + })?; let manifest = serde_json::from_slice::(manifest) .map_err(|source| error(LoadModelErrorKind::InvalidModelFormat, source.into()))?; let metas = &async { - zip.read_file(zip.find_index(manifest.metas_filename())?) - .await + let idx = zip.find_entry_index(manifest.metas_filename())?; + zip.read_file(idx).await } .await .map_err(|source| { @@ -131,13 +134,13 @@ impl Inner { .map(|manifest| { let indices = enum_map! { TalkOperation::PredictDuration => { - zip.find_index(&manifest.predict_duration_filename)? + zip.find_entry_index(&manifest.predict_duration_filename)? } - TalkOperation::PredictIntonation => zip.find_index( + TalkOperation::PredictIntonation => zip.find_entry_index( &manifest.predict_intonation_filename, )?, TalkOperation::Decode => { - zip.find_index(&manifest.decode_filename)? + zip.find_entry_index(&manifest.decode_filename)? } }; @@ -276,7 +279,7 @@ impl A { #[ext] impl async_zip::base::read::seek::ZipFileReader { - fn find_index(&self, filename: &str) -> anyhow::Result { + fn find_entry_index(&self, filename: &str) -> anyhow::Result { let (idx, _) = self .file() .entries()