cargo fmt+一些unsafe

This commit is contained in:
shenjack 2024-05-03 22:45:58 +08:00
parent de70dfa8d9
commit 64d17813c2
Signed by: shenjack
GPG Key ID: 7B1134A979775551
3 changed files with 22 additions and 16 deletions

View File

@ -326,11 +326,11 @@ impl Namer {
for i in (0..256).step_by(64) {
unsafe {
let mut x = u8x64::from_slice(self.val.get_unchecked(i..i+64));
let mut x = u8x64::from_slice(self.val.get_unchecked(i..i + 64));
x = x * simd_181 + simd_160;
x.copy_to_slice(simd_val.get_unchecked_mut(i..i+64));
x.copy_to_slice(simd_val.get_unchecked_mut(i..i + 64));
let y = x & simd_63;
y.copy_to_slice(simd_val_b.get_unchecked_mut(i..i+64));
y.copy_to_slice(simd_val_b.get_unchecked_mut(i..i + 64));
}
}
let mut mod_count = 0;
@ -424,7 +424,6 @@ impl Namer {
) as u32
+ 36;
}
}
#[inline(always)]
@ -533,9 +532,17 @@ impl Namer {
#[inline(always)]
pub fn get_property(&self) -> f32 {
let sum1 = self.name_prop[1..=7].iter().sum::<u32>();
let sum2 = self.name_prop[0];
sum1 as f32 + (sum2 as f32 / 3_f32)
unsafe {
// (self.name_prop.get_unchecked(1)
// + self.name_prop.get_unchecked(2)
// + self.name_prop.get_unchecked(3)
// + self.name_prop.get_unchecked(4)
// + self.name_prop.get_unchecked(5)
// + self.name_prop.get_unchecked(6)
// + self.name_prop.get_unchecked(7)) as f32
// + (*self.name_prop.get_unchecked(0) as f32 / 3_f32)
self.name_prop.get_unchecked(1..=7).iter().sum::<u32>() as f32 + (*self.name_prop.get_unchecked(0) as f32 / 3_f32)
}
}
pub fn get_净化(&self) -> u8 {
@ -745,6 +752,7 @@ mod test {
let prop_vec: Vec<u32> = vec![344, 57, 53, 66, 72, 70, 71, 61];
assert_eq!(namer.name_prop.to_vec(), prop_vec);
assert_eq!(namer.get_property(), 564.6667_f32);
}
#[test]
@ -753,6 +761,7 @@ mod test {
let prop_vec: Vec<u32> = vec![240, 89, 69, 82, 65, 75, 49, 49];
assert_eq!(name.name_prop.to_vec(), prop_vec);
assert_eq!(name.get_property(), 558_f32);
}
#[test]
@ -774,6 +783,5 @@ mod test {
assert_eq!(namer.val.to_vec(), none_update_name.val.to_vec());
assert_eq!(namer.skl_id.to_vec(), none_update_name.skl_id.to_vec());
assert_eq!(namer.skl_freq.to_vec(), none_update_name.skl_freq.to_vec());
}
}

View File

@ -1,4 +1,3 @@
pub mod runners {
use crate::name::Player;
@ -10,6 +9,6 @@ pub mod runners {
/// 应该是一个 Rc4 实例类似物
seed: u32,
/// 所有玩家 (包括 boss)
players: Vec<PlayerGroup>
players: Vec<PlayerGroup>,
}
}

View File

@ -1,7 +1,6 @@
/// 万里长征, 始于足下
mod name;
mod engine;
/// 万里长征, 始于足下
mod name;
mod rc4;
fn main() {