chore: Remove unnecessary type annotations

This commit is contained in:
relrelb 2021-03-12 15:41:16 +02:00 committed by Mike Welsh
parent 3dc5b34706
commit 20d6fcc128
9 changed files with 26 additions and 37 deletions

View File

@ -17,24 +17,14 @@ use std::hash::{Hash, Hasher};
pub enum EventPhase {
/// The event has yet to be fired on the target and is descending the
/// ancestors of the event target.
Capturing,
Capturing = 1,
/// The event is currently firing on the target.
AtTarget,
AtTarget = 2,
/// The event has already fired on the target and is ascending the
/// ancestors of the event target.
Bubbling,
}
impl From<EventPhase> for u32 {
fn from(event: EventPhase) -> u32 {
match event {
EventPhase::Capturing => 1,
EventPhase::AtTarget => 2,
EventPhase::Bubbling => 3,
}
}
Bubbling = 3,
}
/// How this event is allowed to propagate.

View File

@ -130,7 +130,7 @@ pub fn event_phase<'gc>(
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error> {
if let Some(evt) = this.unwrap().as_event() {
let event_phase: u32 = evt.phase().into();
let event_phase = evt.phase() as u32;
return Ok(event_phase.into());
}

View File

@ -102,7 +102,7 @@ impl<'gc> TObject<'gc> for EventObject<'gc> {
let event_type = read.event.event_type();
let bubbles = read.event.is_bubbling();
let cancelable = read.event.is_cancelable();
let phase: u32 = read.event.phase().into();
let phase = read.event.phase() as u32;
Ok(AvmString::new(
mc,

View File

@ -134,7 +134,7 @@ impl<R: Read> AdpcmDecoder<R> {
self.sample_num = (self.sample_num + 1) % 4095;
let data: i32 = self.inner.read::<u32>(self.bits_per_sample as u32)? as i32;
let data = self.inner.read::<u32>(self.bits_per_sample as u32)? as i32;
self.left_step = Self::STEP_TABLE[self.left_step_index as usize];
// (data + 0.5) * step / 2^(bits_per_sample - 2)

View File

@ -132,7 +132,7 @@ impl WebGlRenderBackend {
// Ensure that we don't exceed the max MSAA of this device.
if let Ok(max_samples) = gl2.get_parameter(Gl2::MAX_SAMPLES) {
let max_samples: u32 = max_samples.as_f64().unwrap_or(0.0) as u32;
let max_samples = max_samples.as_f64().unwrap_or(0.0) as u32;
if max_samples > 0 && max_samples < msaa_sample_count {
log::info!("Device only supports {}xMSAA", max_samples);
msaa_sample_count = max_samples;

View File

@ -92,6 +92,7 @@ impl<'a> Reader<'a> {
| (i32::from(self.read_u8()? as i8) << 8)
| (i32::from(self.read_u8()? as i8) << 16))
}
fn read_i32(&mut self) -> Result<i32> {
self.read_encoded_i32()
}

View File

@ -67,21 +67,21 @@ pub trait ReadSwfExt<'a> {
#[inline]
fn read_fixed8(&mut self) -> Result<f32> {
ReadSwfExt::read_i16(self).map(|n| f32::from(n) / 256f32)
Ok((self.read_i16()? as f32) / 256.0)
}
#[inline]
fn read_fixed16(&mut self) -> Result<f64> {
ReadSwfExt::read_i32(self).map(|n| f64::from(n) / 65536f64)
Ok((self.read_i32()? as f64) / 65536.0)
}
#[inline]
fn read_encoded_u32(&mut self) -> Result<u32> {
let mut val = 0u32;
for i in 0..5 {
let byte = ReadSwfExt::read_u8(self)?;
val |= u32::from(byte & 0b01111111) << (i * 7);
if byte & 0b10000000 == 0 {
let mut val: u32 = 0;
for i in (0..35).step_by(7) {
let byte = self.read_u8()? as u32;
val |= (byte & 0b0111_1111) << i;
if byte & 0b1000_0000 == 0 {
break;
}
}
@ -90,23 +90,21 @@ pub trait ReadSwfExt<'a> {
#[inline]
fn read_encoded_i32(&mut self) -> Result<i32> {
let mut n: i32 = 0;
let mut i = 0;
for _ in 0..5 {
let byte: i32 = self.read_u8()?.into();
n |= (byte & 0b0111_1111) << i;
i += 7;
let mut val: i32 = 0;
for i in (0..35).step_by(7) {
let byte = self.read_u8()? as i32;
val |= (byte & 0b0111_1111) << i;
if byte & 0b1000_0000 == 0 {
let i = i + 7;
if i < 32 {
n <<= 32 - i;
n >>= 32 - i;
// Perform sign-extension to allow negative values.
val <<= 32 - i;
val >>= 32 - i;
}
break;
}
}
Ok(n)
Ok(val)
}
#[inline]

View File

@ -560,7 +560,7 @@ impl<'a> Reader<'a> {
pub fn read_rectangle(&mut self) -> Result<Rectangle> {
let mut bits = self.bits();
let num_bits: u32 = bits.read_ubits(5)?;
let num_bits = bits.read_ubits(5)?;
Ok(Rectangle {
x_min: bits.read_sbits_twips(num_bits)?,
x_max: bits.read_sbits_twips(num_bits)?,

View File

@ -2594,7 +2594,7 @@ impl<W: Write> Writer<W> {
fn write_tag_code_and_length(&mut self, tag_code: u16, length: u32) -> Result<()> {
// TODO: Test for tag code/length overflow.
let mut tag_code_and_length: u16 = tag_code << 6;
let mut tag_code_and_length = tag_code << 6;
if length < 0b111111 {
tag_code_and_length |= length as u16;
self.write_u16(tag_code_and_length)?;