diff options
author | iximeow <me@iximeow.net> | 2020-01-03 12:09:00 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2020-01-12 16:10:14 -0800 |
commit | e5c38434423e3f0e936c6b9718063866b3e3347c (patch) | |
tree | a20bf1459308ba73e15e29a869c048245587c775 | |
parent | e4a703859723a674b32968afce9c979f70f0b438 (diff) |
custom hasher for regspec
for hashmaps with heavy traffic keyed on RegSpec, this can be a significant time savings
-rw-r--r-- | src/lib.rs | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -14,18 +14,27 @@ use std::hint::unreachable_unchecked; use yaxpeax_arch::{Arch, Decoder, LengthedInstruction}; #[cfg(feature="use-serde")] -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct RegSpec { pub num: u8, pub bank: RegisterBank } #[cfg(not(feature="use-serde"))] -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct RegSpec { pub num: u8, pub bank: RegisterBank } +use std::hash::Hash; +use std::hash::Hasher; +impl Hash for RegSpec { + fn hash<H: Hasher>(&self, state: &mut H) { + let code = ((self.bank as u16) << 8) | (self.num as u16); + code.hash(state); + } +} + // This is only to select alternate opcode maps for the 0f escape byte. // This often could be treated as a size prefix but in some cases selects // an entirely different operation. |