Skip to content

Commit 1aad9ba

Browse files
committed
avm1: Don't store owned strings in ActivationIdentifier
We can instead always store a `&'a str`.
1 parent e66b387 commit 1aad9ba

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

core/src/avm1/activation.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use gc_arena::{Gc, Mutation};
2020
use indexmap::IndexMap;
2121
use rand::Rng;
2222
use ruffle_macros::istr;
23-
use std::borrow::Cow;
2423
use std::cell::Cell;
2524
use std::cmp::min;
2625
use std::fmt;
@@ -63,7 +62,7 @@ enum FrameControl<'gc> {
6362
#[derive(Clone)]
6463
pub struct ActivationIdentifier<'a> {
6564
parent: Option<&'a ActivationIdentifier<'a>>,
66-
name: Cow<'static, str>,
65+
name: &'a str,
6766
depth: u16,
6867
function_count: u16,
6968
special_count: u8,
@@ -75,36 +74,36 @@ impl fmt::Display for ActivationIdentifier<'_> {
7574
write!(f, "{parent} / ")?;
7675
}
7776

78-
f.write_str(&self.name)?;
77+
f.write_str(self.name)?;
7978

8079
Ok(())
8180
}
8281
}
8382

8483
impl<'a> ActivationIdentifier<'a> {
85-
pub fn root<S: Into<Cow<'static, str>>>(name: S) -> Self {
84+
pub fn root(name: &'a str) -> Self {
8685
Self {
8786
parent: None,
88-
name: name.into(),
87+
name,
8988
depth: 0,
9089
function_count: 0,
9190
special_count: 0,
9291
}
9392
}
9493

95-
pub fn child<S: Into<Cow<'static, str>>>(&'a self, name: S) -> Self {
94+
pub fn child(&'a self, name: &'a str) -> Self {
9695
Self {
9796
parent: Some(self),
98-
name: name.into(),
97+
name,
9998
depth: self.depth + 1,
10099
function_count: self.function_count,
101100
special_count: self.special_count,
102101
}
103102
}
104103

105-
pub fn function<'gc, S: Into<Cow<'static, str>>>(
104+
pub fn function<'gc>(
106105
&'a self,
107-
name: S,
106+
name: &'a str,
108107
reason: ExecutionReason,
109108
max_recursion_depth: u16,
110109
) -> Result<Self, Error<'gc>> {
@@ -124,7 +123,7 @@ impl<'a> ActivationIdentifier<'a> {
124123
};
125124
Ok(Self {
126125
parent: Some(self),
127-
name: name.into(),
126+
name,
128127
depth: self.depth + 1,
129128
function_count,
130129
special_count,
@@ -247,9 +246,9 @@ impl<'a, 'gc> Activation<'a, 'gc> {
247246
}
248247

249248
/// Create a new activation to run a block of code with a given scope.
250-
pub fn with_new_scope<'b, S: Into<Cow<'static, str>>>(
249+
pub fn with_new_scope<'b>(
251250
&'b mut self,
252-
name: S,
251+
name: &'b str,
253252
scope: Gc<'gc, Scope<'gc>>,
254253
) -> Activation<'b, 'gc> {
255254
let id = self.id.child(name);
@@ -329,9 +328,9 @@ impl<'a, 'gc> Activation<'a, 'gc> {
329328
}
330329

331330
/// Add a stack frame that executes code in timeline scope
332-
pub fn run_child_frame_for_action<S: Into<Cow<'static, str>>>(
331+
pub fn run_child_frame_for_action(
333332
&mut self,
334-
name: S,
333+
name: &str,
335334
active_clip: DisplayObject<'gc>,
336335
code: SwfSlice,
337336
) -> Result<ReturnType<'gc>, Error<'gc>> {
@@ -365,9 +364,9 @@ impl<'a, 'gc> Activation<'a, 'gc> {
365364
}
366365

367366
/// Add a stack frame that executes code in initializer scope.
368-
pub fn run_with_child_frame_for_display_object<F, R, S: Into<Cow<'static, str>>>(
367+
pub fn run_with_child_frame_for_display_object<F, R>(
369368
&mut self,
370-
name: S,
369+
name: &str,
371370
active_clip: DisplayObject<'gc>,
372371
swf_version: u8,
373372
function: F,

core/src/avm1/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'gc> Avm1Function<'gc> {
348348
let max_recursion_depth = activation.context.avm1.max_recursion_depth();
349349
let mut frame = Activation::from_action(
350350
activation.context,
351-
activation.id.function(name, reason, max_recursion_depth)?,
351+
activation.id.function(&name, reason, max_recursion_depth)?,
352352
swf_version,
353353
child_scope,
354354
self.constant_pool,

core/src/avm1/runtime.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::string::{AvmString, StringContext};
1212
use crate::tag_utils::SwfSlice;
1313
use crate::{avm1, avm_debug};
1414
use gc_arena::{Collect, Gc, Mutation};
15-
use std::borrow::Cow;
1615
use swf::avm1::read::Reader;
1716
use tracing::instrument;
1817

@@ -136,9 +135,9 @@ impl<'gc> Avm1<'gc> {
136135
/// Add a stack frame that executes code in timeline scope
137136
///
138137
/// This creates a new frame stack.
139-
pub fn run_stack_frame_for_action<S: Into<Cow<'static, str>>>(
138+
pub fn run_stack_frame_for_action(
140139
active_clip: DisplayObject<'gc>,
141-
name: S,
140+
name: &str,
142141
code: SwfSlice,
143142
context: &mut UpdateContext<'gc>,
144143
) {
@@ -284,11 +283,9 @@ impl<'gc> Avm1<'gc> {
284283
return;
285284
}
286285

287-
let mut activation = Activation::from_nothing(
288-
context,
289-
ActivationIdentifier::root(name.to_string()),
290-
active_clip,
291-
);
286+
let name_utf8 = &name.to_utf8_lossy();
287+
let mut activation =
288+
Activation::from_nothing(context, ActivationIdentifier::root(name_utf8), active_clip);
292289

293290
let _ = obj.call_method(name, args, &mut activation, ExecutionReason::Special);
294291
}

core/src/streams.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,11 +1369,12 @@ impl<'gc> NetStream<'gc> {
13691369
match avm_object {
13701370
Some(NetStreamKind::Avm1(object)) => {
13711371
let avm_string_name = AvmString::new_utf8_bytes(context.gc(), variable_name);
1372+
let activation_name = format!("[FLV {avm_string_name}]");
13721373

13731374
let root = context.stage.root_clip().expect("root");
13741375
let mut activation = Avm1Activation::from_nothing(
13751376
context,
1376-
Avm1ActivationIdentifier::root(format!("[FLV {avm_string_name}]")),
1377+
Avm1ActivationIdentifier::root(&activation_name),
13771378
root,
13781379
);
13791380

0 commit comments

Comments
 (0)