Skip to content

Commit 1315d77

Browse files
chore: Replace unnecessary collections with iterators
- Use iterators directly instead of collecting into Vec in DisplayObjectSearchWindow::hovered_debug_rects - Replace Vec collection with Either iterator in Avm2Button::construct_frame - Pass array directly instead of creating Vec in do_reentry external interface test - Avoid collecting JsValues before mapping in RuffleHandle::call_exposed_callback
1 parent 145d52a commit 1315d77

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

core/src/debug_ui.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ impl DebugUi {
194194
}
195195

196196
if let Some(window) = &self.display_object_search {
197-
for (color, object) in window.hovered_debug_rects() {
197+
for (object, color) in window.hovered_debug_rects() {
198198
let object = object.fetch(dynamic_root_set);
199199
let bounds = world_matrix * object.debug_rect_bounds();
200200

201-
draw_debug_rect(context, color, bounds, 5.0);
201+
draw_debug_rect(context, *color, bounds, 5.0);
202202
}
203203
}
204204

core/src/debug_ui/display_object/search.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::display_object::{
88
use egui::collapsing_header::CollapsingState;
99
use egui::color_picker::show_color;
1010
use egui::{Rgba, Ui, Vec2, Window};
11+
use either::Either;
1112
use fnv::FnvHashMap;
1213
use swf::{Point, Twips};
1314

@@ -29,14 +30,11 @@ pub struct DisplayObjectSearchWindow {
2930
}
3031

3132
impl DisplayObjectSearchWindow {
32-
pub fn hovered_debug_rects(&self) -> Vec<(swf::Color, DisplayObjectHandle)> {
33+
pub fn hovered_debug_rects(&self) -> impl Iterator<Item = (&DisplayObjectHandle, &swf::Color)> {
3334
if let Some(hovered_debug_rect) = &self.hovered_debug_rect {
34-
vec![(swf::Color::RED, hovered_debug_rect.clone())]
35+
Either::Left(core::iter::once((hovered_debug_rect, &swf::Color::RED)))
3536
} else {
36-
self.unique_results
37-
.iter()
38-
.map(|(k, v)| (*v, k.clone()))
39-
.collect()
37+
Either::Right(self.unique_results.iter())
4038
}
4139
}
4240

core/src/display_object/avm2_button.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::tag_utils::{SwfMovie, SwfSlice};
2222
use crate::utils::HasPrefixField;
2323
use crate::vminterface::Instantiator;
2424
use core::fmt;
25+
use either::Either;
2526
use gc_arena::barrier::unlock;
2627
use gc_arena::lock::Lock;
2728
use gc_arena::{Collect, Gc, Mutation};
@@ -478,16 +479,14 @@ impl<'gc> TDisplayObject<'gc> for Avm2Button<'gc> {
478479
self.create_state(context, swf::ButtonState::HIT_TEST);
479480

480481
let has_movie_clip_state = {
481-
let objs: Vec<_> = if up_should_fire {
482-
up_state
483-
.as_container()
484-
.unwrap()
485-
.iter_render_list()
486-
.collect()
482+
let objs = if up_should_fire {
483+
Either::Left(up_state.as_container().unwrap().iter_render_list())
487484
} else {
488-
vec![up_state]
485+
Either::Right(core::iter::once(up_state))
489486
};
490-
objs.iter().any(|display| display.as_movie_clip().is_some())
487+
488+
objs.into_iter()
489+
.any(|display| display.as_movie_clip().is_some())
491490
};
492491

493492
let write = Gc::write(context.gc(), self.0);

tests/tests/external_interface/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn do_reentry(context: &mut UpdateContext<'_>, _args: &[ExternalValue]) -> Exter
3333
callback.call(
3434
context,
3535
"callWith",
36-
vec!["trace".into(), "successful reentry!".into()],
36+
["trace".into(), "successful reentry!".into()],
3737
)
3838
} else {
3939
ExternalValue::Null

web/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![deny(clippy::unwrap_used)]
2-
#![allow(clippy::empty_docs)] //False positive in rustc 1.78 beta
32

43
//! Ruffle web frontend.
54
mod audio;
@@ -435,7 +434,7 @@ impl RuffleHandle {
435434
#[expect(clippy::boxed_local)] // for js_bind
436435
args: Box<[JsValue]>,
437436
) -> JsValue {
438-
let args: Vec<_> = args.iter().map(js_to_external_value).collect();
437+
let args = args.iter().map(js_to_external_value);
439438

440439
// Re-entrant callbacks need to return through the hole that was punched through for them
441440
// We record the context of external functions, and then if we get an internal callback

0 commit comments

Comments
 (0)