aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2020-01-03 12:09:00 -0800
committeriximeow <me@iximeow.net>2020-01-12 16:10:14 -0800
commite5c38434423e3f0e936c6b9718063866b3e3347c (patch)
treea20bf1459308ba73e15e29a869c048245587c775 /src/lib.rs
parente4a703859723a674b32968afce9c979f70f0b438 (diff)
custom hasher for regspec
for hashmaps with heavy traffic keyed on RegSpec, this can be a significant time savings
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 81bc4aa..2427f4a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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.