diff --git a/core/src/avm2/object.rs b/core/src/avm2/object.rs index 9c312fdff..417725e70 100644 --- a/core/src/avm2/object.rs +++ b/core/src/avm2/object.rs @@ -589,7 +589,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into> + Clone + Copy let new_slot_id = self .vtable() .unwrap() - .install_const_trait_late(mc, name, value.clone()); + .install_const_trait_late(mc, name, value); self.base_mut(mc) .install_const_slot_late(new_slot_id, value); } diff --git a/core/src/avm2/object/script_object.rs b/core/src/avm2/object/script_object.rs index 5046d2761..f7384a0aa 100644 --- a/core/src/avm2/object/script_object.rs +++ b/core/src/avm2/object/script_object.rs @@ -154,11 +154,9 @@ impl<'gc> ScriptObjectData<'gc> { let value = self.values.get(&local_name); if let Some(value) = value { - return Ok(value.clone()); - } else { - if let Some(proto) = self.proto() { - return proto.get_property_local(multiname, activation); - } + return Ok(*value); + } else if let Some(proto) = self.proto() { + return proto.get_property_local(multiname, activation); } // Special case: Unresolvable properties on dynamic classes are treated @@ -169,9 +167,9 @@ impl<'gc> ScriptObjectData<'gc> { .map(|cls| cls.inner_class_definition().read().is_sealed()) .unwrap_or(false) { - return Err(format!("Cannot get undefined property {:?}", local_name).into()); + Err(format!("Cannot get undefined property {:?}", local_name).into()) } else { - return Ok(Value::Undefined); + Ok(Value::Undefined) } } @@ -277,7 +275,7 @@ impl<'gc> ScriptObjectData<'gc> { let default_slots = vtable.default_slots(); for value in default_slots.deref() { if let Some(value) = value { - self.slots.push(value.clone()); + self.slots.push(*value); } else { self.slots.push(Value::Undefined) } diff --git a/core/src/avm2/property_map.rs b/core/src/avm2/property_map.rs index 55d5a93e6..5d7fed26a 100644 --- a/core/src/avm2/property_map.rs +++ b/core/src/avm2/property_map.rs @@ -74,7 +74,7 @@ impl<'gc, V> PropertyMap<'gc, V> { .iter() .filter_map(|v| { v.iter() - .filter(|(n, _)| name.namespace_set().find(|ns| *ns == n).is_some()) + .filter(|(n, _)| name.namespace_set().any(|ns| *ns == *n)) .map(|(_, v)| v) .next() }) diff --git a/core/src/avm2/scope.rs b/core/src/avm2/scope.rs index 33a3d189c..b0983c59b 100644 --- a/core/src/avm2/scope.rs +++ b/core/src/avm2/scope.rs @@ -117,6 +117,7 @@ impl<'gc> ScopeChain<'gc> { self.domain } + #[allow(clippy::collapsible_if)] pub fn find( &self, multiname: &Multiname<'gc>, @@ -134,11 +135,9 @@ impl<'gc> ScopeChain<'gc> { // But no matter what, we always search traits first. if values.has_trait(multiname) { return Ok(Some(values)); - } else { - if scope.with() || depth == 0 { - if values.has_own_property(multiname) { - return Ok(Some(values)); - } + } else if scope.with() || depth == 0 { + if values.has_own_property(multiname) { + return Ok(Some(values)); } } } @@ -198,6 +197,7 @@ impl<'gc> ScopeStack<'gc> { /// The `global` parameter indicates whether we are on global$init (script initializer). /// When the `global` parameter is true, the scope at depth 0 is considered the global scope, and is /// searched for dynamic properties. + #[allow(clippy::collapsible_if)] pub fn find( &self, multiname: &Multiname<'gc>, @@ -208,14 +208,12 @@ impl<'gc> ScopeStack<'gc> { if values.has_trait(multiname) { return Ok(Some(values)); - } else { + } else if scope.with() || (global && depth == 0) { // We search the dynamic properties if either conditions are met: // 1. Scope is a `with` scope // 2. We are at depth 0 AND we are at global$init (script initializer). - if scope.with() || (global && depth == 0) { - if values.has_own_property(multiname) { - return Ok(Some(values)); - } + if values.has_own_property(multiname) { + return Ok(Some(values)); } } } diff --git a/core/src/avm2/vtable.rs b/core/src/avm2/vtable.rs index f9fa3601e..82a64bbc3 100644 --- a/core/src/avm2/vtable.rs +++ b/core/src/avm2/vtable.rs @@ -86,6 +86,7 @@ impl<'gc> VTable<'gc> { /// /// This should be run during the class finalization step, before instances /// are linked (as instances will further add traits to the list). + #[allow(clippy::if_same_then_else)] pub fn init_vtable( self, defining_class: Option>, @@ -231,25 +232,23 @@ impl<'gc> VTable<'gc> { | TraitKind::Class { slot_id, .. } => { let slot_id = *slot_id; - let value = trait_to_default_value(scope, &trait_data, activation); + let value = trait_to_default_value(scope, trait_data, activation); let value = Some(value); let new_slot_id = if slot_id == 0 { default_slots.push(value); default_slots.len() as u32 - 1 + } else if let Some(Some(_)) = default_slots.get(slot_id as usize) { + // slot_id conflict + default_slots.push(value); + default_slots.len() as u32 - 1 } else { - if let Some(Some(_)) = default_slots.get(slot_id as usize) { - // slot_id conflict - default_slots.push(value); - default_slots.len() as u32 - 1 - } else { - if slot_id as usize >= default_slots.len() { - default_slots.resize_with(slot_id as usize + 1, Default::default); - } - default_slots[slot_id as usize] = value; - slot_id + if slot_id as usize >= default_slots.len() { + default_slots.resize_with(slot_id as usize + 1, Default::default); } - } as u32; + default_slots[slot_id as usize] = value; + slot_id + }; let new_prop = match trait_data.kind() { TraitKind::Slot { .. } | TraitKind::Function { .. } => { @@ -343,8 +342,8 @@ fn trait_to_default_value<'gc>( activation: &mut Activation<'_, 'gc, '_>, ) -> Value<'gc> { match trait_data.kind() { - TraitKind::Slot { default_value, .. } => default_value.clone(), - TraitKind::Const { default_value, .. } => default_value.clone(), + TraitKind::Slot { default_value, .. } => *default_value, + TraitKind::Const { default_value, .. } => *default_value, TraitKind::Function { function, .. } => { FunctionObject::from_function(activation, function.clone(), scope) .unwrap()