Skip to content

Commit 3420365

Browse files
committed
pr
1 parent deafa31 commit 3420365

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/statics.rs

+7-21
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,17 @@ static EVENT_METADATA: LazyLock<Box<[ParsedEventMetadata]>> = LazyLock::new(|| {
8181

8282
let bh = FnvHasher::default();
8383

84-
let mut map: Box<[core::mem::MaybeUninit<ParsedEventMetadata>]> = Box::new_uninit_slice(good_pos + 1);
84+
let mut vec = Vec::with_capacity(good_pos + 1);
8585
next_pos = 0;
8686
while next_pos <= good_pos {
8787
// SAFETY The above code as already validated that events_slice[0..good_pos] are non-null pointers
8888
let next = unsafe { &*events_slice[next_pos] };
8989
let identity_hash = bh.hash_one(&next.identity);
90-
// SAFETY The pointer being written to is valid (we just allocated it above) and aligned (it was allocated with the same type as being written)
91-
unsafe { map[next_pos].as_mut_ptr().write(ParsedEventMetadata { identity_hash, meta: next }) };
90+
vec.push(ParsedEventMetadata { identity_hash, meta: next });
9291
next_pos += 1;
9392
}
94-
// SAFETY We've explicitly initialized all the values now
95-
let mut sorted = unsafe { map.assume_init() };
93+
94+
let mut sorted = vec.into_boxed_slice();
9695
sorted.sort_unstable_by(|a, b| b.cmp(a));
9796
sorted
9897
});
@@ -111,23 +110,10 @@ impl core::cmp::PartialOrd for ParsedEventMetadata {
111110
}
112111
}
113112

113+
// Order by hash only
114114
impl core::cmp::Ord for ParsedEventMetadata {
115115
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
116-
match self.identity_hash.cmp(&other.identity_hash) {
117-
cmp::Ordering::Equal => {
118-
match self.meta.identity == other.meta.identity {
119-
true => cmp::Ordering::Equal,
120-
false => {
121-
// We need to do *something* to sort two different callsites that hit a hash collision.
122-
// TODO: This only works when comparing the static entries generated by the logging macros.
123-
let lhs = &self.meta.identity as *const tracing_core::callsite::Identifier as usize;
124-
let rhs = &other.meta.identity as *const tracing_core::callsite::Identifier as usize;
125-
lhs.cmp(&rhs)
126-
}
127-
}
128-
},
129-
x => x
130-
}
116+
self.identity_hash.cmp(&other.identity_hash)
131117
}
132118
}
133119

@@ -179,7 +165,7 @@ pub(crate) fn event_metadata() -> impl Iterator<Item = <EventMetadataEnumerator
179165
EventMetadataEnumerator{current_index: 0}
180166
}
181167

182-
// Only one test function can be compiled into the module at a time, since the statics they produce are global
168+
// Only one test function can be compiled into the module at a time, since the statics the macro produces are global
183169
#[cfg(test)]
184170
mod test {
185171
use tracing::Level;

0 commit comments

Comments
 (0)