peepmatic: Represent various id types with u16

These ids end up in the automaton, so making them smaller should give us better
data cache locality and also smaller serialized sizes.
This commit is contained in:
Nick Fitzgerald
2020-05-07 13:56:02 -07:00
parent 469104c4d3
commit 210b036320
7 changed files with 27 additions and 27 deletions

View File

@@ -149,11 +149,11 @@ pub enum MatchOp {
/// A canonicalized identifier for a left-hand side value that was bound in a
/// pattern.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct LhsId(pub u32);
pub struct LhsId(pub u16);
/// A canonicalized identifier for a right-hand side value.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct RhsId(pub u32);
pub struct RhsId(pub u16);
/// An action to perform when transitioning between states in the automata.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
@@ -243,18 +243,22 @@ pub enum Action {
mod tests {
use super::*;
// These types all end up in the automaton, so we should take care that they
// are small and don't fill up the data cache (or take up too much
// serialized size).
#[test]
fn match_result_is_4_bytes_in_size() {
fn match_result_size() {
assert_eq!(std::mem::size_of::<MatchResult>(), 4);
}
#[test]
fn match_op_is_12_bytes_in_size() {
assert_eq!(std::mem::size_of::<MatchOp>(), 12);
fn match_op_size() {
assert_eq!(std::mem::size_of::<MatchOp>(), 6);
}
#[test]
fn action_is_20_bytes_in_size() {
assert_eq!(std::mem::size_of::<Action>(), 20);
fn action_size() {
assert_eq!(std::mem::size_of::<Action>(), 16);
}
}