Skip to content

Commit

Permalink
avm2: Make some functions take AvmString directly instead of `impl …
Browse files Browse the repository at this point in the history
…Into<AvmString>`
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Jan 19, 2025
1 parent 87424b1 commit c6c781b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 43 deletions.
32 changes: 13 additions & 19 deletions core/src/avm2/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ impl<'gc> Event<'gc> {
self.event_type
}

pub fn set_event_type<S>(&mut self, event_type: S)
where
S: Into<AvmString<'gc>>,
{
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 {
Expand Down Expand Up @@ -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<AvmString<'gc>>,
) -> Option<&BTreeMap<i32, Vec<EventHandler<'gc>>>> {
self.0.get(&event.into())
fn get_event(&self, event: AvmString<'gc>) -> Option<&BTreeMap<i32, Vec<EventHandler<'gc>>>> {
self.0.get(&event)
}

/// Get all of the event handlers for a given event type, for mutation.
Expand All @@ -195,20 +189,20 @@ impl<'gc> DispatchList<'gc> {
/// list.
fn get_event_mut(
&mut self,
event: impl Into<AvmString<'gc>>,
event: AvmString<'gc>,
) -> &mut BTreeMap<i32, Vec<EventHandler<'gc>>> {
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<AvmString<'gc>>,
event: AvmString<'gc>,
priority: i32,
) -> &mut Vec<EventHandler<'gc>> {
self.0
.entry(event.into())
.entry(event)
.or_default()
.entry(priority)
.or_default()
Expand All @@ -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<AvmString<'gc>> + 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;
Expand All @@ -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<AvmString<'gc>>,
event: AvmString<'gc>,
handler: Object<'gc>,
use_capture: bool,
) {
Expand All @@ -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<AvmString<'gc>>) -> 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() {
Expand All @@ -283,7 +277,7 @@ impl<'gc> DispatchList<'gc> {
/// phases.
pub fn iter_event_handlers<'a>(
&'a mut self,
event: impl Into<AvmString<'gc>>,
event: AvmString<'gc>,
use_capture: bool,
) -> impl 'a + Iterator<Item = Object<'gc>> {
self.get_event_mut(event)
Expand Down
11 changes: 0 additions & 11 deletions core/src/avm2/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,6 @@ impl<'gc> ParamConfig<'gc> {
})
}

pub fn of_type(
name: impl Into<AvmString<'gc>>,
param_type_name: Option<Gc<'gc, Multiname<'gc>>>,
) -> Self {
Self {
param_name: name.into(),
param_type_name,
default_value: None,
}
}

pub fn optional(
name: impl Into<AvmString<'gc>>,
param_type_name: Option<Gc<'gc, Multiname<'gc>>>,
Expand Down
4 changes: 2 additions & 2 deletions core/src/avm2/multiname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AvmString<'gc>>) -> 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,
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/avm2/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
#[no_dynamic]
fn get_string_property_local(
self,
name: impl Into<AvmString<'gc>>,
name: AvmString<'gc>,
activation: &mut Activation<'_, 'gc>,
) -> Result<Value<'gc>, Error<'gc>> {
let name = Multiname::new(activation.avm2().namespaces.public_vm_internal(), name);
Expand Down
14 changes: 4 additions & 10 deletions core/src/avm2/regexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ bitflags! {
}

impl<'gc> RegExp<'gc> {
pub fn new<S>(source: S) -> Self
where
S: Into<AvmString<'gc>>,
{
pub fn new(source: AvmString<'gc>) -> Self {
Self {
source: source.into(),
source,
flags: RegExpFlags::empty(),
last_index: 0,
cached_regex: None,
Expand All @@ -69,12 +66,9 @@ impl<'gc> RegExp<'gc> {
self.source
}

pub fn set_source<S>(&mut self, source: S)
where
S: Into<AvmString<'gc>>,
{
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 {
Expand Down

0 comments on commit c6c781b

Please sign in to comment.