@@ -1337,9 +1337,22 @@ impl Components {
1337
1337
let required_by = unsafe { self . get_required_by_mut ( required) . debug_checked_unwrap ( ) } ;
1338
1338
required_by. insert ( requiree) ;
1339
1339
1340
+ let mut required_components_tmp = RequiredComponents :: default ( ) ;
1340
1341
// SAFETY: The caller ensures that the `requiree` and `required` components are valid.
1341
- let inherited_requirements =
1342
- unsafe { self . register_inherited_required_components ( requiree, required) } ;
1342
+ let inherited_requirements = unsafe {
1343
+ self . register_inherited_required_components (
1344
+ requiree,
1345
+ required,
1346
+ & mut required_components_tmp,
1347
+ )
1348
+ } ;
1349
+
1350
+ // SAFETY: The caller ensures that the `requiree` is valid.
1351
+ let required_components = unsafe {
1352
+ self . get_required_components_mut ( requiree)
1353
+ . debug_checked_unwrap ( )
1354
+ } ;
1355
+ required_components. 0 . extend ( required_components_tmp. 0 ) ;
1343
1356
1344
1357
// Propagate the new required components up the chain to all components that require the requiree.
1345
1358
if let Some ( required_by) = self . get_required_by ( requiree) . cloned ( ) {
@@ -1391,6 +1404,7 @@ impl Components {
1391
1404
& mut self ,
1392
1405
requiree : ComponentId ,
1393
1406
required : ComponentId ,
1407
+ required_components : & mut RequiredComponents ,
1394
1408
) -> Vec < ( ComponentId , RequiredComponent ) > {
1395
1409
// Get required components inherited from the `required` component.
1396
1410
// SAFETY: The caller ensures that the `required` component is valid.
@@ -1414,12 +1428,6 @@ impl Components {
1414
1428
1415
1429
// Register the new required components.
1416
1430
for ( component_id, component) in inherited_requirements. iter ( ) . cloned ( ) {
1417
- // SAFETY: The caller ensures that the `requiree` is valid.
1418
- let required_components = unsafe {
1419
- self . get_required_components_mut ( requiree)
1420
- . debug_checked_unwrap ( )
1421
- } ;
1422
-
1423
1431
// Register the required component for the requiree.
1424
1432
// SAFETY: Component ID and constructor match the ones on the original requiree.
1425
1433
unsafe {
@@ -1520,26 +1528,7 @@ impl Components {
1520
1528
let required_by = unsafe { self . get_required_by_mut ( required) . debug_checked_unwrap ( ) } ;
1521
1529
required_by. insert ( requiree) ;
1522
1530
1523
- // Register the inherited required components for the requiree.
1524
- let required: Vec < ( ComponentId , RequiredComponent ) > = self
1525
- . get_info ( required)
1526
- . unwrap ( )
1527
- . required_components ( )
1528
- . 0
1529
- . iter ( )
1530
- . map ( |( id, component) | ( * id, component. clone ( ) ) )
1531
- . collect ( ) ;
1532
-
1533
- for ( id, component) in required {
1534
- // Register the inherited required components for the requiree.
1535
- // The inheritance depth is increased by `1` since this is a component required by the original required component.
1536
- required_components. register_dynamic (
1537
- id,
1538
- component. constructor . clone ( ) ,
1539
- component. inheritance_depth + 1 ,
1540
- ) ;
1541
- self . get_required_by_mut ( id) . unwrap ( ) . insert ( requiree) ;
1542
- }
1531
+ self . register_inherited_required_components ( requiree, required, required_components) ;
1543
1532
}
1544
1533
1545
1534
#[ inline]
0 commit comments