chore: Appease clippy-beta

This commit is contained in:
Nathan Adams 2023-11-13 13:24:23 +01:00 committed by TÖRÖK Attila
parent 32c65e6460
commit f2b02acf44
5 changed files with 58 additions and 57 deletions

View File

@ -329,7 +329,7 @@ where
let string_separator = separator.coerce_to_string(activation)?;
let mut accum = Vec::with_capacity(vector.length());
for (_, item) in vector.iter().enumerate() {
for item in vector.iter() {
if matches!(item, Value::Undefined) || matches!(item, Value::Null) {
accum.push("null".into());
} else {

View File

@ -3,6 +3,9 @@
// This lint is helpful, but right now we have too many instances of it.
// TODO: Remove this once all instances are fixed.
#![allow(clippy::needless_pass_by_ref_mut)]
// This lint is good in theory, but in AVMs we often need to do `let x = args.get(0); let y = args.get(1);` etc.
// It'd make those much less readable and consistent.
#![allow(clippy::get_first)]
#[macro_use]
mod display_object;

View File

@ -116,9 +116,7 @@ struct WeakSet<'gc, T: 'gc> {
impl<'gc, T: Hash + 'gc> WeakSet<'gc, T> {
fn hash<K: Hash + ?Sized>(build_hasher: &impl BuildHasher, key: &K) -> u64 {
let mut hasher = build_hasher.build_hasher();
key.hash(&mut hasher);
hasher.finish()
build_hasher.hash_one(key)
}
/// Finds the given key in the map.

View File

@ -239,7 +239,7 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> {
}
if frames.len() == 1 {
let image = frames.get(0).unwrap();
let image = frames.first().unwrap();
if opt.output_path == Some(PathBuf::from("-")) {
let mut bytes: Vec<u8> = Vec::new();
image
@ -343,7 +343,7 @@ fn capture_multiple_swfs(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()>
if let Some(parent) = destination.parent() {
let _ = create_dir_all(parent);
}
frames.get(0).unwrap().save(&destination)?;
frames.first().unwrap().save(&destination)?;
} else {
let mut parent: PathBuf = (&output).into();
relative_path.set_extension("");

View File

@ -257,6 +257,57 @@ impl std::ops::MulAssign for Matrix {
}
}
impl From<swf::Matrix> for Matrix {
fn from(matrix: swf::Matrix) -> Self {
Self {
a: matrix.a.to_f32(),
b: matrix.b.to_f32(),
c: matrix.c.to_f32(),
d: matrix.d.to_f32(),
tx: matrix.tx,
ty: matrix.ty,
}
}
}
impl From<Matrix> for swf::Matrix {
fn from(matrix: Matrix) -> Self {
Self {
a: Fixed16::from_f32(matrix.a),
b: Fixed16::from_f32(matrix.b),
c: Fixed16::from_f32(matrix.c),
d: Fixed16::from_f32(matrix.d),
tx: matrix.tx,
ty: matrix.ty,
}
}
}
/// Implements the IEEE-754 "Round to nearest, ties to even" rounding rule.
/// (e.g., both 1.5 and 2.5 will round to 2).
/// This is the rounding method used by Flash for the above transforms.
/// Although this is easy to do on most architectures, Rust provides no standard
/// way to round in this manner (`f32::round` always rounds away from zero).
/// For more info and the below code snippet, see: https://github.com/rust-lang/rust/issues/55107
/// This also clamps out-of-range values and NaN to `i32::MIN`.
/// TODO: Investigate using SSE/wasm intrinsics for this.
fn round_to_i32(f: f32) -> i32 {
if f.is_finite() {
let a = f.abs();
if f < 2_147_483_648.0_f32 {
let k = 1.0 / f32::EPSILON;
let out = if a < k { ((a + k) - k).copysign(f) } else { f };
out as i32
} else {
// Out-of-range clamps to MIN.
i32::MIN
}
} else {
// NaN/Infinity goes to 0.
0
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -907,54 +958,3 @@ mod tests {
),
);
}
impl From<swf::Matrix> for Matrix {
fn from(matrix: swf::Matrix) -> Self {
Self {
a: matrix.a.to_f32(),
b: matrix.b.to_f32(),
c: matrix.c.to_f32(),
d: matrix.d.to_f32(),
tx: matrix.tx,
ty: matrix.ty,
}
}
}
impl From<Matrix> for swf::Matrix {
fn from(matrix: Matrix) -> Self {
Self {
a: Fixed16::from_f32(matrix.a),
b: Fixed16::from_f32(matrix.b),
c: Fixed16::from_f32(matrix.c),
d: Fixed16::from_f32(matrix.d),
tx: matrix.tx,
ty: matrix.ty,
}
}
}
/// Implements the IEEE-754 "Round to nearest, ties to even" rounding rule.
/// (e.g., both 1.5 and 2.5 will round to 2).
/// This is the rounding method used by Flash for the above transforms.
/// Although this is easy to do on most architectures, Rust provides no standard
/// way to round in this manner (`f32::round` always rounds away from zero).
/// For more info and the below code snippet, see: https://github.com/rust-lang/rust/issues/55107
/// This also clamps out-of-range values and NaN to `i32::MIN`.
/// TODO: Investigate using SSE/wasm intrinsics for this.
fn round_to_i32(f: f32) -> i32 {
if f.is_finite() {
let a = f.abs();
if f < 2_147_483_648.0_f32 {
let k = 1.0 / f32::EPSILON;
let out = if a < k { ((a + k) - k).copysign(f) } else { f };
out as i32
} else {
// Out-of-range clamps to MIN.
i32::MIN
}
} else {
// NaN/Infinity goes to 0.
0
}
}