|
1 | 1 | // Module for static variables that are used by the crate.
|
2 | 2 |
|
3 |
| -use std::{cmp, iter::FusedIterator}; |
| 3 | +use std::{cmp, hash::BuildHasher, iter::FusedIterator}; |
4 | 4 |
|
5 | 5 | use crate::_details::EventMetadata;
|
6 | 6 |
|
| 7 | +type FnvHasher = std::hash::BuildHasherDefault::<hashers::fnv::FNV1aHasher64>; |
| 8 | + |
7 | 9 | pub(crate) static GLOBAL_ACTIVITY_SEED: once_cell::sync::Lazy<[u8; 16]> =
|
8 | 10 | once_cell::sync::Lazy::new(|| {
|
9 | 11 | let now = std::time::SystemTime::now()
|
@@ -67,31 +69,19 @@ static EVENT_METADATA: once_cell::sync::Lazy<
|
67 | 69 | next_pos += 1;
|
68 | 70 | }
|
69 | 71 |
|
| 72 | + let bh = FnvHasher::default(); |
| 73 | + |
70 | 74 | let mut map: Box<[core::mem::MaybeUninit<crate::_details::ParsedEventMetadata>]> = Box::new_uninit_slice(good_pos + 1);
|
71 | 75 | next_pos = 0;
|
72 |
| - while next_pos <= good_pos { |
| 76 | + while next_pos < good_pos { |
73 | 77 | 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); |
77 | 79 | map[next_pos].as_mut_ptr().write(crate::_details::ParsedEventMetadata { identity_hash, meta: next });
|
78 | 80 | next_pos += 1;
|
79 | 81 | }
|
80 | 82 | let mut sorted = map.assume_init();
|
81 | 83 | sorted.sort_unstable_by(|a, b| b.cmp(a));
|
82 | 84 | 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 |
95 | 85 | }
|
96 | 86 | });
|
97 | 87 |
|
@@ -148,11 +138,8 @@ impl core::cmp::Ord for crate::_details::ParsedEventMetadata {
|
148 | 138 | }
|
149 | 139 |
|
150 | 140 | 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); |
156 | 143 | let idx = EVENT_METADATA.partition_point(|other| other.identity_hash > identity_hash);
|
157 | 144 | let mut cur = idx;
|
158 | 145 | while cur <EVENT_METADATA.len() {
|
|
0 commit comments