Skip to content

Commit ba90a3a

Browse files
avm2: Remove some uses of static strings
1 parent 403cced commit ba90a3a

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

core/src/avm2/globals/q_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn q_name_constructor<'gc>(
6565
};
6666

6767
if let Value::Object(Object::QNameObject(qname)) = local_arg {
68-
this.set_local_name(activation.gc(), qname.local_name());
68+
this.set_local_name(activation.gc(), qname.local_name(activation.strings()));
6969
} else {
7070
this.set_local_name(activation.gc(), local_arg.coerce_to_string(activation)?);
7171
}
@@ -102,14 +102,14 @@ pub fn q_name_constructor<'gc>(
102102

103103
/// Implements `QName.localName`'s getter
104104
pub fn get_local_name<'gc>(
105-
_activation: &mut Activation<'_, 'gc>,
105+
activation: &mut Activation<'_, 'gc>,
106106
this: Value<'gc>,
107107
_args: &[Value<'gc>],
108108
) -> Result<Value<'gc>, Error<'gc>> {
109109
let this = this.as_object().unwrap();
110110

111111
if let Some(this) = this.as_qname_object() {
112-
return Ok(this.local_name().into());
112+
return Ok(this.local_name(activation.strings()).into());
113113
}
114114

115115
Ok(Value::Undefined)

core/src/avm2/globals/xml.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub fn set_name<'gc>(
253253
// 2. If (Type(name) is Object) and (name.[[Class]] == "QName") and (name.uri == null)
254254
Value::Object(Object::QNameObject(qname)) if qname.is_any_namespace() => {
255255
// a. Let name = name.localName
256-
qname.local_name().into()
256+
qname.local_name(activation.strings()).into()
257257
}
258258
value => value,
259259
};
@@ -269,9 +269,11 @@ pub fn set_name<'gc>(
269269
.as_qname_object()
270270
.unwrap();
271271

272+
let new_local_name = new_name.local_name(activation.strings());
273+
272274
// NOTE: avmplus addition
273-
if !crate::avm2::e4x::is_xml_name(new_name.local_name()) {
274-
return Err(make_error_1117(activation, new_name.local_name()));
275+
if !crate::avm2::e4x::is_xml_name(new_local_name) {
276+
return Err(make_error_1117(activation, new_local_name));
275277
}
276278

277279
// 4. If x.[[Class]] == "processing-instruction", let n.uri be the empty string
@@ -288,7 +290,7 @@ pub fn set_name<'gc>(
288290

289291
// 5. Let x.[[Name]] = n
290292
node.set_namespace(ns, activation.gc());
291-
node.set_local_name(new_name.local_name(), activation.gc());
293+
node.set_local_name(new_local_name, activation.gc());
292294

293295
// NOTE: avmplus addition
294296
if let Some(ns) = ns {
@@ -1303,7 +1305,7 @@ pub fn set_local_name<'gc>(
13031305
// 2. If (Type(name) is Object) and (name.[[Class]] == "QName")
13041306
let name = if let Some(qname) = name.as_object().and_then(|x| x.as_qname_object()) {
13051307
// 2.a. Let name = name.localName
1306-
qname.local_name()
1308+
qname.local_name(activation.strings())
13071309
// 3. Else
13081310
} else {
13091311
// 3.a. Let name = ToString(name)

core/src/avm2/object/proxy_object.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ impl<'gc> TObject<'gc> for ProxyObject<'gc> {
132132
&prop,
133133
&[name
134134
.local_name()
135-
.map(Value::from)
136-
.unwrap_or_else(|| "*".into())],
135+
.unwrap_or_else(|| activation.strings().ascii_char(b'*'))
136+
.into()],
137137
activation,
138138
)?
139139
.coerce_to_boolean())

core/src/avm2/object/qname_object.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ impl<'gc> QNameObject<'gc> {
8989
write_name.set_local_name(local);
9090
}
9191

92-
pub fn local_name(&self) -> AvmString<'gc> {
92+
pub fn local_name(&self, context: &mut StringContext<'gc>) -> AvmString<'gc> {
9393
let name = self.name();
9494

95-
name.local_name().unwrap_or("*".into())
95+
name.local_name().unwrap_or(context.ascii_char(b'*'))
9696
}
9797

9898
pub fn set_is_qname(&self, mc: &Mutation<'gc>, is_qname: bool) {
@@ -159,7 +159,7 @@ impl<'gc> TObject<'gc> for QNameObject<'gc> {
159159
) -> Result<Value<'gc>, Error<'gc>> {
160160
// NOTE: Weird avmplus behavior, get_enumerant_name returns uri first, but get_enumerant_value returns localName first.
161161
Ok(match index {
162-
1 => self.local_name().into(),
162+
1 => self.local_name(activation.strings()).into(),
163163
2 => self
164164
.uri(activation.strings())
165165
.unwrap_or_else(|| activation.strings().empty())

core/src/avm2/value.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ impl<'gc> Value<'gc> {
776776
Value::Bool(true) => "true".into(),
777777
Value::Bool(false) => "false".into(),
778778
Value::Number(n) if n.is_nan() => "NaN".into(),
779-
Value::Number(n) if *n == 0.0 => "0".into(),
779+
Value::Number(n) if *n == 0.0 => activation.strings().ascii_char(b'0'),
780780
Value::Number(n) if *n < 0.0 => AvmString::new_utf8(
781781
activation.gc(),
782782
format!("-{}", Value::Number(-n).coerce_to_string(activation)?),
@@ -806,7 +806,7 @@ impl<'gc> Value<'gc> {
806806
}
807807
Value::Integer(i) => {
808808
if *i >= 0 && *i < 10 {
809-
activation.strings().make_char('0' as u16 + *i as u16)
809+
activation.strings().ascii_char(b'0' + *i as u8)
810810
} else {
811811
AvmString::new_utf8(activation.gc(), i.to_string())
812812
}
@@ -1706,7 +1706,8 @@ impl<'gc> Value<'gc> {
17061706
if let Value::Object(Object::QNameObject(other_qname)) = other {
17071707
return Ok(self_qname.uri(activation.strings())
17081708
== other_qname.uri(activation.strings())
1709-
&& self_qname.local_name() == other_qname.local_name());
1709+
&& self_qname.local_name(activation.strings())
1710+
== other_qname.local_name(activation.strings()));
17101711
}
17111712
}
17121713

0 commit comments

Comments
 (0)