Skip to content

Commit 79bfbcd

Browse files
committed
Change SipHash2-4 -> SipHash1-3
This seems to significantly improves performance. Inspired by rust-lang/rust#107925
1 parent 0105eb7 commit 79bfbcd

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

cli/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use memmap2::Mmap;
1717
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
1818
use once_cell::unsync::OnceCell;
1919
use same_file::{is_same_file, Handle};
20-
use siphasher::sip128::{Hasher128, SipHasher};
20+
use siphasher::sip128::{Hasher128, SipHasher13};
2121
use termcolor::{ColorChoice, StandardStream, WriteColor};
2222
use typst::diag::{FileError, FileResult, SourceError, StrResult};
2323
use typst::eval::Library;
@@ -535,7 +535,7 @@ impl PathHash {
535535
fn new(path: &Path) -> FileResult<Self> {
536536
let f = |e| FileError::from_io(e, path);
537537
let handle = Handle::from_path(path).map_err(f)?;
538-
let mut state = SipHasher::new();
538+
let mut state = SipHasher13::new();
539539
handle.hash(&mut state);
540540
Ok(Self(state.finish128().as_u128()))
541541
}

src/eval/value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::hash::{Hash, Hasher};
55
use std::sync::Arc;
66

77
use ecow::eco_format;
8-
use siphasher::sip128::{Hasher128, SipHasher};
8+
use siphasher::sip128::{Hasher128, SipHasher13};
99

1010
use super::{
1111
cast_to_value, format_str, ops, Args, Array, Cast, CastInfo, Content, Dict, Func,
@@ -313,7 +313,7 @@ where
313313
fn hash128(&self) -> u128 {
314314
// Also hash the TypeId since values with different types but
315315
// equal data should be different.
316-
let mut state = SipHasher::new();
316+
let mut state = SipHasher13::new();
317317
self.type_id().hash(&mut state);
318318
self.hash(&mut state);
319319
state.finish128().as_u128()

src/util/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::num::NonZeroUsize;
1212
use std::path::{Component, Path, PathBuf};
1313
use std::sync::Arc;
1414

15-
use siphasher::sip128::{Hasher128, SipHasher};
15+
use siphasher::sip128::{Hasher128, SipHasher13};
1616

1717
/// Turn a closure into a struct implementing [`Debug`].
1818
pub fn debug<F>(f: F) -> impl Debug
@@ -35,7 +35,7 @@ where
3535

3636
/// Calculate a 128-bit siphash of a value.
3737
pub fn hash128<T: Hash + ?Sized>(value: &T) -> u128 {
38-
let mut state = SipHasher::new();
38+
let mut state = SipHasher13::new();
3939
value.hash(&mut state);
4040
state.finish128().as_u128()
4141
}

0 commit comments

Comments
 (0)