Skip to content

Commit 32ebcf1

Browse files
committed
fix hashing
1 parent 7a0e5be commit 32ebcf1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/statics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ once_cell::sync::Lazy::new(|| {
1616
data
1717
});
1818

19+
static BH: once_cell::sync::Lazy<RandomState> = once_cell::sync::Lazy::new(|| {RandomState::new()});
20+
1921
pub(crate) static EVENT_METADATA: once_cell::sync::Lazy<
2022
Box<[crate::_details::ParsedEventMetadata]>,
2123
> = once_cell::sync::Lazy::new(|| {
@@ -63,12 +65,11 @@ pub(crate) static EVENT_METADATA: once_cell::sync::Lazy<
6365
next_pos += 1;
6466
}
6567

66-
let mut map: Box<[core::mem::MaybeUninit<crate::_details::ParsedEventMetadata>]> = Box::new_uninit_slice(good_pos);
67-
let bh = RandomState::new();
68+
let mut map: Box<[core::mem::MaybeUninit<crate::_details::ParsedEventMetadata>]> = Box::new_uninit_slice(good_pos + 1);
6869
next_pos = 0;
69-
while next_pos < good_pos {
70+
while next_pos <= good_pos {
7071
let next = &*events_slice[next_pos];
71-
map[next_pos].as_mut_ptr().write(crate::_details::ParsedEventMetadata { identity_hash: bh.hash_one(&next.identity), kw: next.kw, event_tag: next.event_tag });
72+
map[next_pos].as_mut_ptr().write(crate::_details::ParsedEventMetadata { identity_hash: BH.hash_one(&next.identity), kw: next.kw, event_tag: next.event_tag });
7273
next_pos += 1;
7374
}
7475
let mut sorted = map.assume_init();
@@ -98,8 +99,7 @@ impl core::cmp::Ord for crate::_details::ParsedEventMetadata {
9899
}
99100

100101
pub(crate) fn get_event_metadata(id: &tracing::callsite::Identifier) -> Option<&'static crate::_details::ParsedEventMetadata> {
101-
let bh = RandomState::new();
102-
let hash = bh.hash_one(id);
102+
let hash = BH.hash_one(id);
103103
let etw_meta = EVENT_METADATA.binary_search_by_key(&hash, |m| { m.identity_hash });
104104
match etw_meta {
105105
Ok(idx) => Some(&EVENT_METADATA[idx]),

0 commit comments

Comments
 (0)