From 0d1e86a233214c1d6552c5b73b41a63e764eb38f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:39:40 -0700 Subject: [PATCH] Box block update sign text to reduce enum size from 268 bytes (large_enum_variant) warning: large size difference between variants --> src/world/mod.rs:54:5 | 54 | / UpdateSignText( 55 | | Position, 56 | | format::Component, 57 | | format::Component, 58 | | format::Component, 59 | | format::Component, 60 | | ), | |_____^ this variant is 268 bytes | = note: `#[warn(clippy::large_enum_variant)]` on by default note: and the second-largest variant is 12 bytes: --> src/world/mod.rs:53:5 | 53 | Remove(Position), | ^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum --> src/world/mod.rs:54:5 | 54 | / UpdateSignText( 55 | | Position, 56 | | format::Component, 57 | | format::Component, 58 | | format::Component, 59 | | format::Component, 60 | | ), | |_____^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant --- src/server/mod.rs | 12 ++++++------ src/world/mod.rs | 15 +++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index f8ed6b4..24edd36 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1576,13 +1576,13 @@ impl Server { nbt.1.get("Text4").unwrap().as_str().unwrap(), ); self.world.add_block_entity_action( - world::BlockEntityAction::UpdateSignText( + world::BlockEntityAction::UpdateSignText(Box::new(( block_update.location, line1, line2, line3, line4, - ), + ))), ); } //10 => // Unused @@ -1610,13 +1610,13 @@ impl Server { format::convert_legacy(&mut update_sign.line3); format::convert_legacy(&mut update_sign.line4); self.world - .add_block_entity_action(world::BlockEntityAction::UpdateSignText( + .add_block_entity_action(world::BlockEntityAction::UpdateSignText(Box::new(( update_sign.location, update_sign.line1, update_sign.line2, update_sign.line3, update_sign.line4, - )); + )))); } fn on_sign_update_u16(&mut self, mut update_sign: packet::play::clientbound::UpdateSign_u16) { @@ -1625,13 +1625,13 @@ impl Server { format::convert_legacy(&mut update_sign.line3); format::convert_legacy(&mut update_sign.line4); self.world - .add_block_entity_action(world::BlockEntityAction::UpdateSignText( + .add_block_entity_action(world::BlockEntityAction::UpdateSignText(Box::new(( Position::new(update_sign.x, update_sign.y as i32, update_sign.z), update_sign.line1, update_sign.line2, update_sign.line3, update_sign.line4, - )); + )))); } fn on_player_info_string( diff --git a/src/world/mod.rs b/src/world/mod.rs index 92336e3..7cdb72b 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -52,11 +52,13 @@ pub enum BlockEntityAction { Create(Position), Remove(Position), UpdateSignText( - Position, - format::Component, - format::Component, - format::Component, - format::Component, + Box<( + Position, + format::Component, + format::Component, + format::Component, + format::Component, + )>, ), } @@ -240,7 +242,8 @@ impl World { } } } - BlockEntityAction::UpdateSignText(pos, line1, line2, line3, line4) => { + BlockEntityAction::UpdateSignText(bx) => { + let (pos, line1, line2, line3, line4) = *bx; if let Some(chunk) = self.chunks.get(&CPos(pos.x >> 4, pos.z >> 4)) { if let Some(entity) = chunk.block_entities.get(&pos) { if let Some(sign) = m.get_component_mut(*entity, sign_info) {