HUD paint: build the sprite key in one reused buffer

paint() runs for every drawn HUD call each frame and made a fresh String per
sprite to look it up in the atlas: sprite.to_string() for a mob_effect and
format!("gui/sprites/{sprite}") otherwise. One buffer outside the loop keeps
the same keys without the allocation.

Co-Authored-By: Hermes Agent (Nous Research) <[email protected]>
This commit is contained in:
AlexanderandHermes Agent committed 2026-10-28 10:33:46 +03:00
1 parent b6c936f82b
commit 4bf633e8a9
1 file changed
+9 -5
+9 -5
View File
@@ -801,6 +801,8 @@ impl HealthHud {
/// nausea blits (their blending needs the screen-effect pipeline).
pub fn paint(batch: &mut crate::hud::HudBatch, atlas: &crate::hud::HudAtlas, draws: &[GuiDraw]) {
let mut stack = vec![IDENTITY];
// One buffer for the sprite keys, instead of a string per drawn sprite.
let mut name = String::new();
for d in draws {
let start = batch.vertices.len();
let pose = *stack.last().unwrap_or(&IDENTITY);
@@ -817,12 +819,14 @@ pub fn paint(batch: &mut crate::hud::HudBatch, atlas: &crate::hud::HudAtlas, dra
} => {
// Effect sprites belong to the mob_effect atlas directory;
// the other blitSprite ids refer to GUI sprites.
let name = if sprite.starts_with("mob_effect/") {
sprite.to_string()
name.clear();
if sprite.starts_with("mob_effect/") {
name.push_str(sprite);
} else {
format!("gui/sprites/{sprite}")
};
let Some(mut r) = atlas.sprites.get(&name).copied() else {
name.push_str("gui/sprites/");
name.push_str(sprite);
}
let Some(mut r) = atlas.sprites.get(name.as_str()).copied() else {
continue;
};
if let Some([sw, sh, u, v]) = *region {