@@ -311,35 +311,42 @@ pub fn default_created_space_views(
311
311
312
312
// `AutoSpawnHeuristic::SpawnClassWithHighestScoreForRoot` means we're competing with other candidates for the same root.
313
313
if let AutoSpawnHeuristic :: SpawnClassWithHighestScoreForRoot ( score) = spawn_heuristic {
314
- let mut should_spawn_new = true ;
314
+ // [`SpaceViewBlueprint`]s don't implement clone so wrap in an option so we can
315
+ // track whether or not we've consumed it.
316
+ let mut candidate_still_considered = Some ( candidate) ;
317
+
315
318
for ( prev_candidate, prev_spawn_heuristic) in & mut space_views {
316
- if prev_candidate. space_origin == candidate. space_origin {
317
- #[ allow( clippy:: match_same_arms) ]
318
- match prev_spawn_heuristic {
319
- AutoSpawnHeuristic :: SpawnClassWithHighestScoreForRoot ( prev_score) => {
320
- // If we're competing with a candidate for the same root, we either replace a lower score, or we yield.
321
- should_spawn_new = false ;
322
- if * prev_score < score {
323
- // Replace the previous candidate with this one.
324
- * prev_candidate = candidate. clone ( ) ;
325
- * prev_spawn_heuristic = spawn_heuristic;
326
- } else {
327
- // We have a lower score, so we don't spawn.
319
+ if let Some ( candidate) = candidate_still_considered. take ( ) {
320
+ if prev_candidate. space_origin == candidate. space_origin {
321
+ #[ allow( clippy:: match_same_arms) ]
322
+ match prev_spawn_heuristic {
323
+ AutoSpawnHeuristic :: SpawnClassWithHighestScoreForRoot ( prev_score) => {
324
+ // If we're competing with a candidate for the same root, we either replace a lower score, or we yield.
325
+ if * prev_score < score {
326
+ // Replace the previous candidate with this one.
327
+ * prev_candidate = candidate;
328
+ * prev_spawn_heuristic = spawn_heuristic;
329
+ }
330
+
331
+ // Either way we're done with this candidate.
328
332
break ;
329
333
}
330
- }
331
- AutoSpawnHeuristic :: AlwaysSpawn => {
332
- // We can live side by side with always-spawn candidates.
333
- }
334
- AutoSpawnHeuristic :: NeverSpawn => {
335
- // Never spawn candidates should not be in the list, this is weird!
336
- // But let's not fail on this since our heuristics are not perfect anyways.
334
+ AutoSpawnHeuristic :: AlwaysSpawn => {
335
+ // We can live side by side with always-spawn candidates.
336
+ }
337
+ AutoSpawnHeuristic :: NeverSpawn => {
338
+ // Never spawn candidates should not be in the list, this is weird!
339
+ // But let's not fail on this since our heuristics are not perfect anyways.
340
+ }
337
341
}
338
342
}
343
+
344
+ // If we didn't hit the break condition, continue to consider the candidate
345
+ candidate_still_considered = Some ( candidate) ;
339
346
}
340
347
}
341
348
342
- if should_spawn_new {
349
+ if let Some ( candidate ) = candidate_still_considered {
343
350
// Spatial views with images get extra treatment as well.
344
351
if is_spatial_2d_class ( candidate. class_identifier ( ) ) {
345
352
#[ derive( Hash , PartialEq , Eq ) ]
0 commit comments