Skip to content

Commit

Permalink
Box up all Packet variants.
Browse files Browse the repository at this point in the history
Previously, the Packet enum was a whopping 4,264 bytes in size (over a page!).
Not only is this just bad for performance (lots of memmoving), but I think it was
also causing weird stack overflow segfaults on my machine.
  • Loading branch information
BGR360 committed Jan 18, 2022
1 parent 9fca022 commit a79d5d8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions protocol/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ macro_rules! state_packets {
$(
$(
$(
$name($state::$dir::$name),
$name(Box<$state::$dir::$name>),
)*
)+
)+
Expand Down Expand Up @@ -184,7 +184,7 @@ macro_rules! state_packets {
packet.$field = Serializable::read_from(&mut buf)?;
}
)+
Result::Ok(Option::Some(Packet::$name(packet)))
Result::Ok(Option::Some(Packet::$name(Box::new(packet))))
},
)*
_ => Result::Ok(Option::None)
Expand Down
2 changes: 1 addition & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ macro_rules! handle_packet {
}) => (
match $pck {
$(
protocol::packet::Packet::$packet(val) => $s.$func(val),
protocol::packet::Packet::$packet(val) => $s.$func(*val),
)*
_ => {},
}
Expand Down

0 comments on commit a79d5d8

Please sign in to comment.