Skip to content

Commit c397c2f

Browse files
committed
interning
1 parent a0972c2 commit c397c2f

File tree

18 files changed

+351
-448
lines changed

18 files changed

+351
-448
lines changed

crates/bevy_app/src/app.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use bevy_ecs::{
44
prelude::*,
55
schedule::{
66
apply_state_transition, common_conditions::run_once as run_once_condition,
7-
run_enter_schedule, BoxedScheduleLabel, IntoSystemConfigs, IntoSystemSetConfigs,
8-
ScheduleLabel,
7+
run_enter_schedule, IntoSystemConfigs, IntoSystemSetConfigs, ScheduleId, ScheduleLabel,
98
},
109
};
1110
use bevy_utils::{tracing::debug, HashMap, HashSet};
@@ -70,7 +69,7 @@ pub struct App {
7069
/// The schedule that runs the main loop of schedule execution.
7170
///
7271
/// This is initially set to [`Main`].
73-
pub main_schedule_label: BoxedScheduleLabel,
72+
pub main_schedule_label: ScheduleId,
7473
sub_apps: HashMap<AppLabelId, SubApp>,
7574
plugin_registry: Vec<Box<dyn Plugin>>,
7675
plugin_name_added: HashSet<String>,
@@ -156,7 +155,7 @@ impl SubApp {
156155

157156
/// Runs the [`SubApp`]'s default schedule.
158157
pub fn run(&mut self) {
159-
self.app.world.run_schedule(&*self.app.main_schedule_label);
158+
self.app.world.run_schedule(self.app.main_schedule_label);
160159
self.app.world.clear_trackers();
161160
}
162161

@@ -219,7 +218,7 @@ impl App {
219218
sub_apps: HashMap::default(),
220219
plugin_registry: Vec::default(),
221220
plugin_name_added: Default::default(),
222-
main_schedule_label: Box::new(Main),
221+
main_schedule_label: Main.as_label(),
223222
building_plugin_depth: 0,
224223
}
225224
}
@@ -241,7 +240,7 @@ impl App {
241240
{
242241
#[cfg(feature = "trace")]
243242
let _bevy_main_update_span = info_span!("main app").entered();
244-
self.world.run_schedule(&*self.main_schedule_label);
243+
self.world.run_schedule(self.main_schedule_label);
245244
}
246245
for (_label, sub_app) in self.sub_apps.iter_mut() {
247246
#[cfg(feature = "trace")]
@@ -745,7 +744,7 @@ impl App {
745744
pub fn sub_app_mut(&mut self, label: impl AppLabel) -> &mut App {
746745
match self.get_sub_app_mut(label) {
747746
Ok(app) => app,
748-
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label.as_str()),
747+
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label),
749748
}
750749
}
751750

@@ -767,7 +766,7 @@ impl App {
767766
pub fn sub_app(&self, label: impl AppLabel) -> &App {
768767
match self.get_sub_app(label) {
769768
Ok(app) => app,
770-
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label.as_str()),
769+
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label),
771770
}
772771
}
773772

@@ -837,11 +836,12 @@ impl App {
837836
) -> &mut Self {
838837
let mut schedules = self.world.resource_mut::<Schedules>();
839838

840-
if schedules.get(&label).is_none() {
841-
schedules.insert(label.dyn_clone(), Schedule::new());
839+
let id = ScheduleId::of(&label);
840+
if !schedules.contains(&id) {
841+
schedules.insert(id, Schedule::new());
842842
}
843843

844-
let schedule = schedules.get_mut(&label).unwrap();
844+
let schedule = schedules.get_mut(&id).unwrap();
845845
// Call the function f, passing in the schedule retrieved
846846
f(schedule);
847847

crates/bevy_app/src/main_schedule.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl MainScheduleOrder {
125125
let index = self
126126
.labels
127127
.iter()
128-
.position(|current| (**current).eq(&after))
128+
.position(|current| (current.as_dyn_eq()).dyn_eq(after.as_dyn_eq()))
129129
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
130130
self.labels.insert(index + 1, Box::new(schedule));
131131
}

crates/bevy_derive/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,5 @@ pub fn derive_app_label(input: TokenStream) -> TokenStream {
208208
let input = syn::parse_macro_input!(input as syn::DeriveInput);
209209
let mut trait_path = BevyManifest::default().get_path("bevy_app");
210210
trait_path.segments.push(format_ident!("AppLabel").into());
211-
derive_label(input, &trait_path, "app_label")
211+
derive_label(input, &trait_path)
212212
}

crates/bevy_ecs/macros/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ mod set;
66
mod states;
77

88
use crate::{fetch::derive_world_query_impl, set::derive_set};
9-
use bevy_macro_utils::{
10-
derive_boxed_label, ensure_no_collision, get_named_struct_fields, BevyManifest,
11-
};
9+
use bevy_macro_utils::{derive_label, ensure_no_collision, get_named_struct_fields, BevyManifest};
1210
use proc_macro::TokenStream;
1311
use proc_macro2::Span;
1412
use quote::{format_ident, quote};
@@ -435,7 +433,7 @@ pub fn derive_schedule_label(input: TokenStream) -> TokenStream {
435433
trait_path
436434
.segments
437435
.push(format_ident!("ScheduleLabel").into());
438-
derive_boxed_label(input, &trait_path)
436+
derive_label(input, &trait_path)
439437
}
440438

441439
/// Derive macro generating an impl of the trait `SystemSet`.

crates/bevy_ecs/macros/src/set.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ pub fn derive_set(input: syn::DeriveInput, trait_path: &syn::Path) -> TokenStrea
2323
);
2424

2525
(quote! {
26-
impl #impl_generics #trait_path for #ident #ty_generics #where_clause {
27-
fn dyn_clone(&self) -> std::boxed::Box<dyn #trait_path> {
28-
std::boxed::Box::new(std::clone::Clone::clone(self))
29-
}
30-
}
26+
impl #impl_generics #trait_path for #ident #ty_generics #where_clause {}
3127
})
3228
.into()
3329
}

crates/bevy_ecs/src/schedule/config.rs

+42-38
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
schedule::{
55
condition::{BoxedCondition, Condition},
66
graph_utils::{Ambiguity, Dependency, DependencyKind, GraphInfo},
7-
set::{BoxedSystemSet, IntoSystemSet, SystemSet},
7+
set::{IntoSystemSet, SystemSet, SystemSetUntyped},
88
},
99
system::{BoxedSystem, IntoSystem, System},
1010
};
@@ -20,7 +20,7 @@ fn new_condition<M>(condition: impl Condition<M>) -> BoxedCondition {
2020
Box::new(condition_system)
2121
}
2222

23-
fn ambiguous_with(graph_info: &mut GraphInfo, set: BoxedSystemSet) {
23+
fn ambiguous_with(graph_info: &mut GraphInfo, set: SystemSetUntyped) {
2424
match &mut graph_info.ambiguous_with {
2525
detection @ Ambiguity::Check => {
2626
*detection = Ambiguity::IgnoreWithSet(vec![set]);
@@ -83,20 +83,20 @@ impl SystemConfigs {
8383
})
8484
}
8585

86-
pub(crate) fn in_set_inner(&mut self, set: BoxedSystemSet) {
86+
pub(crate) fn in_set_inner(&mut self, set: SystemSetUntyped) {
8787
match self {
8888
SystemConfigs::SystemConfig(config) => {
8989
config.graph_info.sets.push(set);
9090
}
9191
SystemConfigs::Configs { configs, .. } => {
9292
for config in configs {
93-
config.in_set_inner(set.dyn_clone());
93+
config.in_set_inner(set);
9494
}
9595
}
9696
}
9797
}
9898

99-
fn before_inner(&mut self, set: BoxedSystemSet) {
99+
fn before_inner(&mut self, set: SystemSetUntyped) {
100100
match self {
101101
SystemConfigs::SystemConfig(config) => {
102102
config
@@ -106,13 +106,13 @@ impl SystemConfigs {
106106
}
107107
SystemConfigs::Configs { configs, .. } => {
108108
for config in configs {
109-
config.before_inner(set.dyn_clone());
109+
config.before_inner(set);
110110
}
111111
}
112112
}
113113
}
114114

115-
fn after_inner(&mut self, set: BoxedSystemSet) {
115+
fn after_inner(&mut self, set: SystemSetUntyped) {
116116
match self {
117117
SystemConfigs::SystemConfig(config) => {
118118
config
@@ -122,7 +122,7 @@ impl SystemConfigs {
122122
}
123123
SystemConfigs::Configs { configs, .. } => {
124124
for config in configs {
125-
config.after_inner(set.dyn_clone());
125+
config.after_inner(set);
126126
}
127127
}
128128
}
@@ -141,14 +141,14 @@ impl SystemConfigs {
141141
}
142142
}
143143

144-
fn ambiguous_with_inner(&mut self, set: BoxedSystemSet) {
144+
fn ambiguous_with_inner(&mut self, set: SystemSetUntyped) {
145145
match self {
146146
SystemConfigs::SystemConfig(config) => {
147147
ambiguous_with(&mut config.graph_info, set);
148148
}
149149
SystemConfigs::Configs { configs, .. } => {
150150
for config in configs {
151-
config.ambiguous_with_inner(set.dyn_clone());
151+
config.ambiguous_with_inner(set);
152152
}
153153
}
154154
}
@@ -302,25 +302,26 @@ impl IntoSystemConfigs<()> for SystemConfigs {
302302

303303
#[track_caller]
304304
fn in_set(mut self, set: impl SystemSet) -> Self {
305+
let set = SystemSetUntyped::of(&set);
305306
assert!(
306307
set.system_type().is_none(),
307308
"adding arbitrary systems to a system type set is not allowed"
308309
);
309310

310-
self.in_set_inner(set.dyn_clone());
311+
self.in_set_inner(set);
311312

312313
self
313314
}
314315

315316
fn before<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
316-
let set = set.into_system_set();
317-
self.before_inner(set.dyn_clone());
317+
let set = SystemSetUntyped::of(&set.into_system_set());
318+
self.before_inner(set);
318319
self
319320
}
320321

321322
fn after<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
322-
let set = set.into_system_set();
323-
self.after_inner(set.dyn_clone());
323+
let set = SystemSetUntyped::of(&set.into_system_set());
324+
self.after_inner(set);
324325
self
325326
}
326327

@@ -330,8 +331,8 @@ impl IntoSystemConfigs<()> for SystemConfigs {
330331
}
331332

332333
fn ambiguous_with<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
333-
let set = set.into_system_set();
334-
self.ambiguous_with_inner(set.dyn_clone());
334+
let set = SystemSetUntyped::of(&set.into_system_set());
335+
self.ambiguous_with_inner(set);
335336
self
336337
}
337338

@@ -382,13 +383,13 @@ all_tuples!(impl_system_collection, 1, 20, P, S);
382383

383384
/// A [`SystemSet`] with scheduling metadata.
384385
pub struct SystemSetConfig {
385-
pub(super) set: BoxedSystemSet,
386+
pub(super) set: SystemSetUntyped,
386387
pub(super) graph_info: GraphInfo,
387388
pub(super) conditions: Vec<BoxedCondition>,
388389
}
389390

390391
impl SystemSetConfig {
391-
fn new(set: BoxedSystemSet) -> Self {
392+
fn new(set: SystemSetUntyped) -> Self {
392393
// system type sets are automatically populated
393394
// to avoid unintentionally broad changes, they cannot be configured
394395
assert!(
@@ -445,11 +446,11 @@ pub trait IntoSystemSetConfig: Sized {
445446

446447
impl<S: SystemSet> IntoSystemSetConfig for S {
447448
fn into_config(self) -> SystemSetConfig {
448-
SystemSetConfig::new(Box::new(self))
449+
SystemSetConfig::new(SystemSetUntyped::of(&self))
449450
}
450451
}
451452

452-
impl IntoSystemSetConfig for BoxedSystemSet {
453+
impl IntoSystemSetConfig for SystemSetUntyped {
453454
fn into_config(self) -> SystemSetConfig {
454455
SystemSetConfig::new(self)
455456
}
@@ -462,27 +463,28 @@ impl IntoSystemSetConfig for SystemSetConfig {
462463

463464
#[track_caller]
464465
fn in_set(mut self, set: impl SystemSet) -> Self {
466+
let set = SystemSetUntyped::of(&set);
465467
assert!(
466468
set.system_type().is_none(),
467469
"adding arbitrary systems to a system type set is not allowed"
468470
);
469-
self.graph_info.sets.push(Box::new(set));
471+
self.graph_info.sets.push(set);
470472
self
471473
}
472474

473475
fn before<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
474-
self.graph_info.dependencies.push(Dependency::new(
475-
DependencyKind::Before,
476-
Box::new(set.into_system_set()),
477-
));
476+
let set = SystemSetUntyped::of(&set.into_system_set());
477+
self.graph_info
478+
.dependencies
479+
.push(Dependency::new(DependencyKind::Before, set));
478480
self
479481
}
480482

481483
fn after<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
482-
self.graph_info.dependencies.push(Dependency::new(
483-
DependencyKind::After,
484-
Box::new(set.into_system_set()),
485-
));
484+
let set = SystemSetUntyped::of(&set.into_system_set());
485+
self.graph_info
486+
.dependencies
487+
.push(Dependency::new(DependencyKind::After, set));
486488
self
487489
}
488490

@@ -492,7 +494,8 @@ impl IntoSystemSetConfig for SystemSetConfig {
492494
}
493495

494496
fn ambiguous_with<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
495-
ambiguous_with(&mut self.graph_info, Box::new(set.into_system_set()));
497+
let set = SystemSetUntyped::of(&set.into_system_set());
498+
ambiguous_with(&mut self.graph_info, set);
496499
self
497500
}
498501

@@ -561,45 +564,46 @@ impl IntoSystemSetConfigs for SystemSetConfigs {
561564

562565
#[track_caller]
563566
fn in_set(mut self, set: impl SystemSet) -> Self {
567+
let set = SystemSetUntyped::of(&set);
564568
assert!(
565569
set.system_type().is_none(),
566570
"adding arbitrary systems to a system type set is not allowed"
567571
);
568572
for config in &mut self.sets {
569-
config.graph_info.sets.push(set.dyn_clone());
573+
config.graph_info.sets.push(set);
570574
}
571575

572576
self
573577
}
574578

575579
fn before<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
576-
let set = set.into_system_set();
580+
let set = SystemSetUntyped::of(&set.into_system_set());
577581
for config in &mut self.sets {
578582
config
579583
.graph_info
580584
.dependencies
581-
.push(Dependency::new(DependencyKind::Before, set.dyn_clone()));
585+
.push(Dependency::new(DependencyKind::Before, set));
582586
}
583587

584588
self
585589
}
586590

587591
fn after<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
588-
let set = set.into_system_set();
592+
let set = SystemSetUntyped::of(&set.into_system_set());
589593
for config in &mut self.sets {
590594
config
591595
.graph_info
592596
.dependencies
593-
.push(Dependency::new(DependencyKind::After, set.dyn_clone()));
597+
.push(Dependency::new(DependencyKind::After, set));
594598
}
595599

596600
self
597601
}
598602

599603
fn ambiguous_with<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
600-
let set = set.into_system_set();
604+
let set = SystemSetUntyped::of(&set.into_system_set());
601605
for config in &mut self.sets {
602-
ambiguous_with(&mut config.graph_info, set.dyn_clone());
606+
ambiguous_with(&mut config.graph_info, set);
603607
}
604608

605609
self

0 commit comments

Comments
 (0)