Skip to content

Commit 85d92d3

Browse files
avm2: Make some functions take AvmString directly instead of impl Into<AvmString>
1 parent b388929 commit 85d92d3

File tree

5 files changed

+20
-43
lines changed

5 files changed

+20
-43
lines changed

core/src/avm2/events.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,8 @@ impl<'gc> Event<'gc> {
9393
self.event_type
9494
}
9595

96-
pub fn set_event_type<S>(&mut self, event_type: S)
97-
where
98-
S: Into<AvmString<'gc>>,
99-
{
100-
self.event_type = event_type.into();
96+
pub fn set_event_type(&mut self, event_type: AvmString<'gc>) {
97+
self.event_type = event_type;
10198
}
10299

103100
pub fn is_bubbling(&self) -> bool {
@@ -182,11 +179,8 @@ impl<'gc> DispatchList<'gc> {
182179

183180
/// Get all of the event handlers for a given event type, if such a type
184181
/// exists.
185-
fn get_event(
186-
&self,
187-
event: impl Into<AvmString<'gc>>,
188-
) -> Option<&BTreeMap<i32, Vec<EventHandler<'gc>>>> {
189-
self.0.get(&event.into())
182+
fn get_event(&self, event: AvmString<'gc>) -> Option<&BTreeMap<i32, Vec<EventHandler<'gc>>>> {
183+
self.0.get(&event)
190184
}
191185

192186
/// Get all of the event handlers for a given event type, for mutation.
@@ -195,20 +189,20 @@ impl<'gc> DispatchList<'gc> {
195189
/// list.
196190
fn get_event_mut(
197191
&mut self,
198-
event: impl Into<AvmString<'gc>>,
192+
event: AvmString<'gc>,
199193
) -> &mut BTreeMap<i32, Vec<EventHandler<'gc>>> {
200-
self.0.entry(event.into()).or_default()
194+
self.0.entry(event).or_default()
201195
}
202196

203197
/// Get a single priority level of event handlers for a given event type,
204198
/// for mutation.
205199
fn get_event_priority_mut(
206200
&mut self,
207-
event: impl Into<AvmString<'gc>>,
201+
event: AvmString<'gc>,
208202
priority: i32,
209203
) -> &mut Vec<EventHandler<'gc>> {
210204
self.0
211-
.entry(event.into())
205+
.entry(event)
212206
.or_default()
213207
.entry(priority)
214208
.or_default()
@@ -222,14 +216,14 @@ impl<'gc> DispatchList<'gc> {
222216
/// be added again, and this function will silently fail.
223217
pub fn add_event_listener(
224218
&mut self,
225-
event: impl Into<AvmString<'gc>> + Clone,
219+
event: AvmString<'gc>,
226220
priority: i32,
227221
handler: Object<'gc>,
228222
use_capture: bool,
229223
) {
230224
let new_handler = EventHandler::new(handler, use_capture);
231225

232-
if let Some(event_sheaf) = self.get_event(event.clone()) {
226+
if let Some(event_sheaf) = self.get_event(event) {
233227
for (_other_prio, other_set) in event_sheaf.iter() {
234228
if other_set.contains(&new_handler) {
235229
return;
@@ -247,7 +241,7 @@ impl<'gc> DispatchList<'gc> {
247241
/// removed from any priority in the list.
248242
pub fn remove_event_listener(
249243
&mut self,
250-
event: impl Into<AvmString<'gc>>,
244+
event: AvmString<'gc>,
251245
handler: Object<'gc>,
252246
use_capture: bool,
253247
) {
@@ -261,7 +255,7 @@ impl<'gc> DispatchList<'gc> {
261255
}
262256

263257
/// Determine if there are any event listeners in this dispatch list.
264-
pub fn has_event_listener(&self, event: impl Into<AvmString<'gc>>) -> bool {
258+
pub fn has_event_listener(&self, event: AvmString<'gc>) -> bool {
265259
if let Some(event_sheaf) = self.get_event(event) {
266260
for (_prio, set) in event_sheaf.iter() {
267261
if !set.is_empty() {
@@ -283,7 +277,7 @@ impl<'gc> DispatchList<'gc> {
283277
/// phases.
284278
pub fn iter_event_handlers<'a>(
285279
&'a mut self,
286-
event: impl Into<AvmString<'gc>>,
280+
event: AvmString<'gc>,
287281
use_capture: bool,
288282
) -> impl 'a + Iterator<Item = Object<'gc>> {
289283
self.get_event_mut(event)

core/src/avm2/method.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ impl<'gc> ParamConfig<'gc> {
9292
})
9393
}
9494

95-
pub fn of_type(
96-
name: impl Into<AvmString<'gc>>,
97-
param_type_name: Option<Gc<'gc, Multiname<'gc>>>,
98-
) -> Self {
99-
Self {
100-
param_name: name.into(),
101-
param_type_name,
102-
default_value: None,
103-
}
104-
}
105-
10695
pub fn optional(
10796
name: impl Into<AvmString<'gc>>,
10897
param_type_name: Option<Gc<'gc, Multiname<'gc>>>,

core/src/avm2/multiname.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,10 @@ impl<'gc> Multiname<'gc> {
362362
}
363363

364364
/// Creates a new Multiname with the `MultinameFlags::ATTRIBUTE` flag.
365-
pub fn attribute(ns: Namespace<'gc>, name: impl Into<AvmString<'gc>>) -> Self {
365+
pub fn attribute(ns: Namespace<'gc>, name: AvmString<'gc>) -> Self {
366366
Self {
367367
ns: NamespaceSet::single(ns),
368-
name: Some(name.into()),
368+
name: Some(name),
369369
param: None,
370370
flags: MultinameFlags::ATTRIBUTE,
371371
}

core/src/avm2/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
239239
#[no_dynamic]
240240
fn get_string_property_local(
241241
self,
242-
name: impl Into<AvmString<'gc>>,
242+
name: AvmString<'gc>,
243243
activation: &mut Activation<'_, 'gc>,
244244
) -> Result<Value<'gc>, Error<'gc>> {
245245
let name = Multiname::new(activation.avm2().namespaces.public_vm_internal(), name);

core/src/avm2/regexp.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ bitflags! {
5252
}
5353

5454
impl<'gc> RegExp<'gc> {
55-
pub fn new<S>(source: S) -> Self
56-
where
57-
S: Into<AvmString<'gc>>,
58-
{
55+
pub fn new(source: AvmString<'gc>) -> Self {
5956
Self {
60-
source: source.into(),
57+
source,
6158
flags: RegExpFlags::empty(),
6259
last_index: 0,
6360
cached_regex: None,
@@ -69,12 +66,9 @@ impl<'gc> RegExp<'gc> {
6966
self.source
7067
}
7168

72-
pub fn set_source<S>(&mut self, source: S)
73-
where
74-
S: Into<AvmString<'gc>>,
75-
{
69+
pub fn set_source(&mut self, source: AvmString<'gc>) {
7670
self.cached_regex = None;
77-
self.source = source.into();
71+
self.source = source;
7872
}
7973

8074
pub fn flags(&self) -> RegExpFlags {

0 commit comments

Comments
 (0)