Skip to content

Commit

Permalink
Rust 1.77の新機能を導入する (#771)
Browse files Browse the repository at this point in the history
* dtolnay/syn#1502 をコメントに残す

* `round_ties_even_`を削除

* コピーしてきた`chunk_by`の実装を削除
  • Loading branch information
qryxip committed Apr 9, 2024
1 parent fa630ce commit f6e2227
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
102 changes: 0 additions & 102 deletions crates/voicevox_core/src/engine/full_context_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Item> {
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<usize>) {
if self.slice.is_empty() {
(0, Some(0))
} else {
(1, Some(self.slice.len()))
}
}
}

#[easy_ext::ext(TChunkBy)]
impl<T> [T] {
pub fn chunk_by<F>(&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::*;
Expand Down
1 change: 0 additions & 1 deletion crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod infer;
mod macros;
mod manifest;
mod metas;
mod numerics;
mod result;
mod synthesizer;
mod task;
Expand Down
17 changes: 0 additions & 17 deletions crates/voicevox_core/src/numerics.rs

This file was deleted.

5 changes: 2 additions & 3 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f6e2227

Please sign in to comment.