From f6e22279894f55234e13f9ee44703d8fc523cdd7 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Wed, 10 Apr 2024 05:54:52 +0900 Subject: [PATCH] =?UTF-8?q?Rust=201.77=E3=81=AE=E6=96=B0=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E3=82=92=E5=B0=8E=E5=85=A5=E3=81=99=E3=82=8B=20(#771)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * dtolnay/syn#1502 をコメントに残す * `round_ties_even_`を削除 * コピーしてきた`chunk_by`の実装を削除 --- Cargo.toml | 2 +- .../src/engine/full_context_label.rs | 102 ------------------ crates/voicevox_core/src/lib.rs | 1 - crates/voicevox_core/src/numerics.rs | 17 --- crates/voicevox_core/src/synthesizer.rs | 5 +- 5 files changed, 3 insertions(+), 124 deletions(-) delete mode 100644 crates/voicevox_core/src/numerics.rs diff --git a/Cargo.toml b/Cargo.toml index 5c2ceb5be..21b9a0ac9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ chrono = { version = "0.4.26", default-features = false } clap = "4.0.10" color-eyre = "0.6.2" colorchoice = "1.0.0" -cstr = "0.2.11" +cstr = "0.2.11" # https://github.com/dtolnay/syn/issues/1502 derive-getters = "0.2.0" derive-new = "0.5.9" derive_more = "0.99.17" diff --git a/crates/voicevox_core/src/engine/full_context_label.rs b/crates/voicevox_core/src/engine/full_context_label.rs index 06cfdd0fd..8b87048e5 100644 --- a/crates/voicevox_core/src/engine/full_context_label.rs +++ b/crates/voicevox_core/src/engine/full_context_label.rs @@ -177,108 +177,6 @@ pub fn mora_to_text(consonant: Option<&str>, vowel: &str) -> String { engine::mora2text(&mora_text).to_string() } -// FIXME: Rust 1.77の新機能導入と共にこれを消す -#[allow(unused_imports)] -mod chunk_by { - // Implementations in this module were copied from - // [Rust](https://github.com/rust-lang/rust/blob/746a58d4359786e4aebb372a30829706fa5a968f/library/core/src/slice/iter.rs). - - // MIT License Notice - - // Permission is hereby granted, free of charge, to any - // person obtaining a copy of this software and associated - // documentation files (the "Software"), to deal in the - // Software without restriction, including without - // limitation the rights to use, copy, modify, merge, - // publish, distribute, sublicense, and/or sell copies of - // the Software, and to permit persons to whom the Software - // is furnished to do so, subject to the following - // conditions: - // - // The above copyright notice and this permission notice - // shall be included in all copies or substantial portions - // of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF - // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED - // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT - // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR - // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - // DEALINGS IN THE SOFTWARE. - - pub struct ChunkBy<'a, T, P> { - slice: &'a [T], - predicate: P, - } - impl<'a, T, P> ChunkBy<'a, T, P> { - pub(super) fn new(slice: &'a [T], predicate: P) -> Self { - ChunkBy { slice, predicate } - } - } - impl<'a, T, P> Iterator for ChunkBy<'a, T, P> - where - P: FnMut(&T, &T) -> bool, - { - type Item = &'a [T]; - - #[inline] - fn next(&mut self) -> Option { - if self.slice.is_empty() { - None - } else { - let mut len = 1; - let mut iter = self.slice.windows(2); - while let Some([l, r]) = iter.next() { - if (self.predicate)(l, r) { - len += 1 - } else { - break; - } - } - let (head, tail) = self.slice.split_at(len); - self.slice = tail; - Some(head) - } - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - if self.slice.is_empty() { - (0, Some(0)) - } else { - (1, Some(self.slice.len())) - } - } - } - - #[easy_ext::ext(TChunkBy)] - impl [T] { - pub fn chunk_by(&self, pred: F) -> ChunkBy<'_, T, F> - where - F: FnMut(&T, &T) -> bool, - { - ChunkBy::new(self, pred) - } - } - - #[cfg(test)] - mod tests { - use super::TChunkBy; - - #[test] - fn chunk_by() { - let mut split = [0, 0, 1, 1, 1, -5].chunk_by(|a, b| a == b); - assert_eq!(split.next(), Some([0, 0].as_slice())); - assert_eq!(split.next(), Some([1, 1, 1].as_slice())); - assert_eq!(split.next(), Some([-5].as_slice())); - assert_eq!(split.next(), None); - } - } -} - #[cfg(test)] mod tests { use rstest_reuse::*; diff --git a/crates/voicevox_core/src/lib.rs b/crates/voicevox_core/src/lib.rs index 7cb4abaf1..29efba8f1 100644 --- a/crates/voicevox_core/src/lib.rs +++ b/crates/voicevox_core/src/lib.rs @@ -8,7 +8,6 @@ mod infer; mod macros; mod manifest; mod metas; -mod numerics; mod result; mod synthesizer; mod task; diff --git a/crates/voicevox_core/src/numerics.rs b/crates/voicevox_core/src/numerics.rs deleted file mode 100644 index b01c4d6a5..000000000 --- a/crates/voicevox_core/src/numerics.rs +++ /dev/null @@ -1,17 +0,0 @@ -use easy_ext::ext; - -#[ext(F32Ext)] -pub(crate) impl f32 { - /// 偶数丸めを行う。 - /// - /// [`round_ties_even` feature]で追加される予定の`f32::round_ties_even`の代用。 - /// - /// [`round_ties_even` feature]: https://github.com/rust-lang/rust/pull/95317 - fn round_ties_even_(self) -> f32 { - let mut rounded = self.round(); - if (self - rounded).abs() == 0.5 { - rounded = 2. * (self / 2.).round(); - } - rounded - } -} diff --git a/crates/voicevox_core/src/synthesizer.rs b/crates/voicevox_core/src/synthesizer.rs index a3c34489e..e6ef3a9bb 100644 --- a/crates/voicevox_core/src/synthesizer.rs +++ b/crates/voicevox_core/src/synthesizer.rs @@ -91,7 +91,6 @@ pub(crate) mod blocking { status::Status, InferenceSessionOptions, }, - numerics::F32Ext as _, text_analyzer::{KanaAnalyzer, OpenJTalkAnalyzer, TextAnalyzer}, AccentPhraseModel, AudioQueryModel, FullcontextExtractor, Result, StyleId, SupportedDevices, SynthesisOptions, VoiceModelId, VoiceModelMeta, @@ -302,8 +301,8 @@ pub(crate) mod blocking { // VOICEVOX ENGINEと挙動を合わせるため、四捨五入ではなく偶数丸めをする // // https://github.com/VOICEVOX/voicevox_engine/issues/552 - let phoneme_length = ((*phoneme_length * RATE).round_ties_even_() / speed_scale) - .round_ties_even_() as usize; + let phoneme_length = ((*phoneme_length * RATE).round_ties_even() / speed_scale) + .round_ties_even() as usize; let phoneme_id = phoneme_data_list[i].phoneme_id(); for _ in 0..phoneme_length {