Skip to content

Commit 3bd32bc

Browse files
Deduplicate Default Font Data (#20397)
# Objective The data for the default font is included twice with `include_bytes!`. This is not a big problem as the data gets deduplicated at some point during optimization, so this PR only saves 50 bytes~ instead of 20kb, but we're still wasting time during compilation copying this file around twice. # Solution Use the `DEFAULT_FONT_DATA` constant introduced in #14406 for setting the default font instead of including the bytes a second time via `load_internal_binary_asset`.
1 parent 599e015 commit 3bd32bc

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

crates/bevy_text/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ pub mod prelude {
6767
}
6868

6969
use bevy_app::{prelude::*, AnimationSystems};
70-
#[cfg(feature = "default_font")]
71-
use bevy_asset::{load_internal_binary_asset, Handle};
7270
use bevy_asset::{AssetApp, AssetEventSystems};
7371
use bevy_ecs::prelude::*;
7472
use bevy_render::{
@@ -141,11 +139,11 @@ impl Plugin for TextPlugin {
141139
}
142140

143141
#[cfg(feature = "default_font")]
144-
load_internal_binary_asset!(
145-
app,
146-
Handle::default(),
147-
"FiraMono-subset.ttf",
148-
|bytes: &[u8], _path: String| { Font::try_from_bytes(bytes.to_vec()).unwrap() }
149-
);
142+
{
143+
use bevy_asset::{AssetId, Assets};
144+
let mut assets = app.world_mut().resource_mut::<Assets<_>>();
145+
let asset = Font::try_from_bytes(DEFAULT_FONT_DATA.to_vec()).unwrap();
146+
assets.insert(AssetId::default(), asset);
147+
};
150148
}
151149
}

0 commit comments

Comments
 (0)