This commit is contained in:
2024-01-30 02:09:24 -05:00
parent 224bd7a699
commit 760e36bdb1
2 changed files with 22 additions and 0 deletions

View File

@@ -18,3 +18,23 @@ macro_rules! invoke_once {
} }
} }
pub struct OnDrop<F: FnOnce()>(Option<F>);
impl<F: FnOnce()> OnDrop<F> {
pub fn new(fun: F) -> Self {
Self(Some(fun))
}
}
impl<F: FnOnce()> Drop for OnDrop<F> {
fn drop(&mut self) {
if let Some(fun) = self.0.take() {
fun()
}
}
}

View File

@@ -26,6 +26,7 @@ pub const fn hash32(bytes: &[u32]) -> u64 {
} }
//noinspection DuplicatedCode //noinspection DuplicatedCode
#[inline(always)]
pub const fn hash64(bytes: &[u64]) -> u64 { pub const fn hash64(bytes: &[u64]) -> u64 {
let mut hash = INITIAL_STATE; let mut hash = INITIAL_STATE;
let mut i = 0; let mut i = 0;
@@ -38,6 +39,7 @@ pub const fn hash64(bytes: &[u64]) -> u64 {
} }
//noinspection DuplicatedCode //noinspection DuplicatedCode
#[inline(always)]
pub const fn hash_utf8(bytes: &[u8]) -> u64 { pub const fn hash_utf8(bytes: &[u8]) -> u64 {
let mut hash = INITIAL_STATE; let mut hash = INITIAL_STATE;
let mut i = 0; let mut i = 0;