Skip to content

Commit 6781cb5

Browse files
committed
avm2: Elide some copies when iterating vtable properties
1 parent d598929 commit 6781cb5

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

core/src/avm2/amf.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ pub fn recursive_serialize<'gc>(
189189
if let Some(static_properties) = static_properties {
190190
let vtable = obj.vtable();
191191
// TODO: respect versioning
192-
let mut props = vtable.public_properties();
193192
// Flash appears to use vtable iteration order, but we sort ours
194193
// to make our test output consistent.
195-
props.sort_by_key(|(name, _)| name.to_utf8_lossy().to_string());
194+
let mut props = vtable.public_properties().collect::<Vec<_>>();
195+
props.sort_by_key(|(name, _)| *name);
196+
196197
for (name, prop) in props {
197198
if let Property::Method { .. } = prop {
198199
continue;

core/src/avm2/vtable.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,11 @@ impl<'gc> VTable<'gc> {
549549
)
550550
}
551551

552-
pub fn public_properties(self) -> Vec<(AvmString<'gc>, Property)> {
553-
let mut props = Vec::new();
554-
555-
for (name, ns, prop) in self.resolved_traits().iter() {
556-
if ns.is_public() {
557-
props.push((name, *prop));
558-
}
559-
}
560-
props
552+
pub fn public_properties(self) -> impl Iterator<Item = (AvmString<'gc>, Property)> {
553+
self.resolved_traits()
554+
.iter()
555+
.filter(|(_, ns, _)| ns.is_public())
556+
.map(|(name, _, prop)| (name, *prop))
561557
}
562558
}
563559

core/src/debug_ui/avm2.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,12 @@ impl Avm2ObjectWindow {
302302
activation: &mut Activation<'_, 'gc>,
303303
ui: &mut Ui,
304304
) {
305-
let mut entries = Vec::<(String, Namespace<'gc>, Property)>::new();
306-
// We can't access things whilst we iterate the vtable, so clone and sort it all here
307-
let vtable = object.vtable();
308-
309-
for (name, ns, prop) in vtable.resolved_traits().iter() {
310-
entries.push((name.to_string(), ns, *prop));
311-
}
305+
let mut entries: Vec<(Cow<'gc, str>, Namespace<'gc>, Property)> = object
306+
.vtable()
307+
.resolved_traits()
308+
.iter()
309+
.map(|(name, ns, prop)| (name.as_wstr().to_utf8_lossy(), ns, *prop))
310+
.collect();
312311
entries.sort_by(|a, b| a.0.cmp(&b.0));
313312

314313
ui.horizontal(|ui| {

0 commit comments

Comments
 (0)