From c6c781b4e9c7303694f15f2a1aef47e2cbaed02e Mon Sep 17 00:00:00 2001 From: Lord-McSweeney Date: Sun, 19 Jan 2025 14:15:45 -0800 Subject: [PATCH] avm2: Make some functions take `AvmString` directly instead of `impl Into` --- core/src/avm2/events.rs | 32 +++++++++++++------------------- core/src/avm2/method.rs | 11 ----------- core/src/avm2/multiname.rs | 4 ++-- core/src/avm2/object.rs | 2 +- core/src/avm2/regexp.rs | 14 ++++---------- 5 files changed, 20 insertions(+), 43 deletions(-) diff --git a/core/src/avm2/events.rs b/core/src/avm2/events.rs index 62f7b48dbc59..0a014526f9c6 100644 --- a/core/src/avm2/events.rs +++ b/core/src/avm2/events.rs @@ -93,11 +93,8 @@ impl<'gc> Event<'gc> { self.event_type } - pub fn set_event_type(&mut self, event_type: S) - where - S: Into>, - { - self.event_type = event_type.into(); + pub fn set_event_type(&mut self, event_type: AvmString<'gc>) { + self.event_type = event_type; } pub fn is_bubbling(&self) -> bool { @@ -182,11 +179,8 @@ impl<'gc> DispatchList<'gc> { /// Get all of the event handlers for a given event type, if such a type /// exists. - fn get_event( - &self, - event: impl Into>, - ) -> Option<&BTreeMap>>> { - self.0.get(&event.into()) + fn get_event(&self, event: AvmString<'gc>) -> Option<&BTreeMap>>> { + self.0.get(&event) } /// Get all of the event handlers for a given event type, for mutation. @@ -195,20 +189,20 @@ impl<'gc> DispatchList<'gc> { /// list. fn get_event_mut( &mut self, - event: impl Into>, + event: AvmString<'gc>, ) -> &mut BTreeMap>> { - self.0.entry(event.into()).or_default() + self.0.entry(event).or_default() } /// Get a single priority level of event handlers for a given event type, /// for mutation. fn get_event_priority_mut( &mut self, - event: impl Into>, + event: AvmString<'gc>, priority: i32, ) -> &mut Vec> { self.0 - .entry(event.into()) + .entry(event) .or_default() .entry(priority) .or_default() @@ -222,14 +216,14 @@ impl<'gc> DispatchList<'gc> { /// be added again, and this function will silently fail. pub fn add_event_listener( &mut self, - event: impl Into> + Clone, + event: AvmString<'gc>, priority: i32, handler: Object<'gc>, use_capture: bool, ) { let new_handler = EventHandler::new(handler, use_capture); - if let Some(event_sheaf) = self.get_event(event.clone()) { + if let Some(event_sheaf) = self.get_event(event) { for (_other_prio, other_set) in event_sheaf.iter() { if other_set.contains(&new_handler) { return; @@ -247,7 +241,7 @@ impl<'gc> DispatchList<'gc> { /// removed from any priority in the list. pub fn remove_event_listener( &mut self, - event: impl Into>, + event: AvmString<'gc>, handler: Object<'gc>, use_capture: bool, ) { @@ -261,7 +255,7 @@ impl<'gc> DispatchList<'gc> { } /// Determine if there are any event listeners in this dispatch list. - pub fn has_event_listener(&self, event: impl Into>) -> bool { + pub fn has_event_listener(&self, event: AvmString<'gc>) -> bool { if let Some(event_sheaf) = self.get_event(event) { for (_prio, set) in event_sheaf.iter() { if !set.is_empty() { @@ -283,7 +277,7 @@ impl<'gc> DispatchList<'gc> { /// phases. pub fn iter_event_handlers<'a>( &'a mut self, - event: impl Into>, + event: AvmString<'gc>, use_capture: bool, ) -> impl 'a + Iterator> { self.get_event_mut(event) diff --git a/core/src/avm2/method.rs b/core/src/avm2/method.rs index ee07272bc107..61642bce0402 100644 --- a/core/src/avm2/method.rs +++ b/core/src/avm2/method.rs @@ -92,17 +92,6 @@ impl<'gc> ParamConfig<'gc> { }) } - pub fn of_type( - name: impl Into>, - param_type_name: Option>>, - ) -> Self { - Self { - param_name: name.into(), - param_type_name, - default_value: None, - } - } - pub fn optional( name: impl Into>, param_type_name: Option>>, diff --git a/core/src/avm2/multiname.rs b/core/src/avm2/multiname.rs index e6fbc0e346b6..5fafd692d738 100644 --- a/core/src/avm2/multiname.rs +++ b/core/src/avm2/multiname.rs @@ -362,10 +362,10 @@ impl<'gc> Multiname<'gc> { } /// Creates a new Multiname with the `MultinameFlags::ATTRIBUTE` flag. - pub fn attribute(ns: Namespace<'gc>, name: impl Into>) -> Self { + pub fn attribute(ns: Namespace<'gc>, name: AvmString<'gc>) -> Self { Self { ns: NamespaceSet::single(ns), - name: Some(name.into()), + name: Some(name), param: None, flags: MultinameFlags::ATTRIBUTE, } diff --git a/core/src/avm2/object.rs b/core/src/avm2/object.rs index c6a87c1ccab3..7fad80470c9a 100644 --- a/core/src/avm2/object.rs +++ b/core/src/avm2/object.rs @@ -239,7 +239,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into> + Clone + Copy #[no_dynamic] fn get_string_property_local( self, - name: impl Into>, + name: AvmString<'gc>, activation: &mut Activation<'_, 'gc>, ) -> Result, Error<'gc>> { let name = Multiname::new(activation.avm2().namespaces.public_vm_internal(), name); diff --git a/core/src/avm2/regexp.rs b/core/src/avm2/regexp.rs index 125e713e466d..6e267cd6bd0d 100644 --- a/core/src/avm2/regexp.rs +++ b/core/src/avm2/regexp.rs @@ -52,12 +52,9 @@ bitflags! { } impl<'gc> RegExp<'gc> { - pub fn new(source: S) -> Self - where - S: Into>, - { + pub fn new(source: AvmString<'gc>) -> Self { Self { - source: source.into(), + source, flags: RegExpFlags::empty(), last_index: 0, cached_regex: None, @@ -69,12 +66,9 @@ impl<'gc> RegExp<'gc> { self.source } - pub fn set_source(&mut self, source: S) - where - S: Into>, - { + pub fn set_source(&mut self, source: AvmString<'gc>) { self.cached_regex = None; - self.source = source.into(); + self.source = source; } pub fn flags(&self) -> RegExpFlags {