Skip to content

Commit d3c774d

Browse files
committed
fix
1 parent 9ea0b60 commit d3c774d

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

src/statics.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Module for static variables that are used by the crate.
22

3-
use std::{cmp, iter::FusedIterator};
3+
use std::{cmp, hash::BuildHasher, iter::FusedIterator};
44

55
use crate::_details::EventMetadata;
66

7+
type FnvHasher = std::hash::BuildHasherDefault::<hashers::fnv::FNV1aHasher64>;
8+
79
pub(crate) static GLOBAL_ACTIVITY_SEED: once_cell::sync::Lazy<[u8; 16]> =
810
once_cell::sync::Lazy::new(|| {
911
let now = std::time::SystemTime::now()
@@ -67,31 +69,19 @@ static EVENT_METADATA: once_cell::sync::Lazy<
6769
next_pos += 1;
6870
}
6971

72+
let bh = FnvHasher::default();
73+
7074
let mut map: Box<[core::mem::MaybeUninit<crate::_details::ParsedEventMetadata>]> = Box::new_uninit_slice(good_pos + 1);
7175
next_pos = 0;
72-
while next_pos <= good_pos {
76+
while next_pos < good_pos {
7377
let next = &*events_slice[next_pos];
74-
let identity_hash = hashers::fnv::fnv1a64(
75-
core::slice::from_raw_parts(&next.identity as *const tracing_core::callsite::Identifier as *const u8,
76-
core::mem::size_of::<tracing_core::callsite::Identifier>()));
78+
let identity_hash = bh.hash_one(&next.identity);
7779
map[next_pos].as_mut_ptr().write(crate::_details::ParsedEventMetadata { identity_hash, meta: next });
7880
next_pos += 1;
7981
}
8082
let mut sorted = map.assume_init();
8183
sorted.sort_unstable_by(|a, b| b.cmp(a));
8284
sorted
83-
84-
// Sort the good pointers by their values
85-
// let good_events = &mut events_slice[..good_pos + 1];
86-
// good_events.sort_by(|a, b| {
87-
// let lhs = &**a;
88-
// let rhs = &**b;
89-
// lhs.cmp(rhs)
90-
// });
91-
92-
// let wrapper = start as *const EventMetadataPtr;
93-
// let slice = core::ptr::slice_from_raw_parts(wrapper, good_pos + 1);
94-
// &*slice
9585
}
9686
});
9787

@@ -148,11 +138,8 @@ impl core::cmp::Ord for crate::_details::ParsedEventMetadata {
148138
}
149139

150140
pub(crate) fn get_event_metadata(id: &tracing::callsite::Identifier) -> Option<&'static crate::_details::EventMetadata> {
151-
let identity_hash = hashers::fnv::fnv1a64(unsafe {
152-
core::slice::from_raw_parts(
153-
id as *const tracing_core::callsite::Identifier as *const u8,
154-
core::mem::size_of::<tracing_core::callsite::Identifier>())
155-
});
141+
let bh = FnvHasher::default();
142+
let identity_hash = bh.hash_one(id);
156143
let idx = EVENT_METADATA.partition_point(|other| other.identity_hash > identity_hash);
157144
let mut cur = idx;
158145
while cur <EVENT_METADATA.len() {

0 commit comments

Comments
 (0)