Skip to content

Commit 746c37d

Browse files
avm1/avm2: Add AvmString::from_static_wstr and use it
Replaces the old `From<&'static WStr>` impl on AvmString
1 parent f39234f commit 746c37d

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

core/src/avm1/globals/bevel_filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ fn method<'gc>(
515515
}
516516
GET_TYPE => {
517517
let type_: &WStr = this.type_().into();
518-
AvmString::from(type_).into()
518+
AvmString::from_static_wstr(activation.gc(), type_).into()
519519
}
520520
SET_TYPE => {
521521
this.set_type(activation, args.get(0))?;

core/src/avm1/globals/displacement_map_filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ fn method<'gc>(
418418
}
419419
GET_MODE => {
420420
let mode: &WStr = this.mode().into();
421-
AvmString::from(mode).into()
421+
AvmString::from_static_wstr(activation.gc(), mode).into()
422422
}
423423
SET_MODE => {
424424
this.set_mode(activation, args.get(0))?;

core/src/avm1/globals/gradient_filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ fn method<'gc>(
506506
}
507507
GET_TYPE => {
508508
let type_: &WStr = this.type_().into();
509-
AvmString::from(type_).into()
509+
AvmString::from_static_wstr(activation.gc(), type_).into()
510510
}
511511
SET_TYPE => {
512512
this.set_type(activation, args.get(0))?;

core/src/avm2/globals/flash/display/bitmap.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::avm2::globals::flash::display::display_object::initialize_for_allocat
66
use crate::avm2::object::{BitmapDataObject, ClassObject, Object, TObject};
77
use crate::avm2::value::Value;
88
use crate::avm2::Error;
9+
use crate::string::AvmString;
910
use ruffle_render::bitmap::PixelSnapping;
1011
use ruffle_wstr::WStr;
1112

@@ -156,15 +157,18 @@ pub fn set_bitmap_data<'gc>(
156157

157158
/// Stub `Bitmap.pixelSnapping`'s getter
158159
pub fn get_pixel_snapping<'gc>(
159-
_activation: &mut Activation<'_, 'gc>,
160+
activation: &mut Activation<'_, 'gc>,
160161
this: Value<'gc>,
161162
_args: &[Value<'gc>],
162163
) -> Result<Value<'gc>, Error<'gc>> {
163164
let this = this.as_object().unwrap();
164165

165166
if let Some(bitmap) = this.as_display_object().and_then(|dobj| dobj.as_bitmap()) {
166167
let value: &WStr = bitmap.pixel_snapping().into();
167-
return Ok(Value::String(value.into()));
168+
return Ok(Value::String(AvmString::from_static_wstr(
169+
activation.gc(),
170+
value,
171+
)));
168172
}
169173
Ok(Value::Undefined)
170174
}

core/src/string/avm_string.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ impl<'gc> AvmString<'gc> {
6868
}
6969
}
7070

71+
pub fn from_static_wstr(gc_context: &Mutation<'gc>, string: &'static WStr) -> Self {
72+
let repr = AvmStringRepr::from_raw_static(string, false);
73+
74+
Self {
75+
source: Source::Managed(Gc::new(gc_context, repr)),
76+
}
77+
}
78+
7179
pub fn substring(mc: &Mutation<'gc>, string: AvmString<'gc>, start: usize, end: usize) -> Self {
7280
match string.source {
7381
Source::Managed(repr) => {
@@ -175,15 +183,6 @@ impl From<&'static str> for AvmString<'_> {
175183
}
176184
}
177185

178-
impl From<&'static WStr> for AvmString<'_> {
179-
#[inline]
180-
fn from(str: &'static WStr) -> Self {
181-
Self {
182-
source: Source::Static(str),
183-
}
184-
}
185-
}
186-
187186
impl Deref for AvmString<'_> {
188187
type Target = WStr;
189188
#[inline]

0 commit comments

Comments
 (0)