style: Avoid linear search to check for custom property presence

The test-case in the next patch from 10s to a couple hundred
milliseconds on my machine. No behavior change other than that.

Differential Revision: https://phabricator.services.mozilla.com/D175612
This commit is contained in:
Emilio Cobos Álvarez 2023-04-18 11:09:31 +00:00 committed by Martin Robinson
parent 9a97080dbb
commit bedf574092
2 changed files with 109 additions and 77 deletions

View file

@ -17,7 +17,6 @@ extern crate thin_vec;
use std::alloc::Layout;
#[cfg(debug_assertions)]
use std::any::TypeId;
#[cfg(debug_assertions)]
use std::collections::HashSet;
use std::ffi::CString;
use std::marker::PhantomData;
@ -426,6 +425,21 @@ impl<T: ToShmem> ToShmem for Option<T> {
}
}
impl<T: ToShmem, S> ToShmem for HashSet<T, S>
where
Self: Default,
{
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> Result<Self> {
if !self.is_empty() {
return Err(format!(
"ToShmem failed for HashSet: We only support empty sets \
(we don't expect custom properties in UA sheets, they're observable by content)",
))
}
Ok(ManuallyDrop::new(Self::default()))
}
}
impl<T: 'static + ToShmem> ToShmem for Arc<T> {
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> Result<Self> {
// Assert that we don't encounter any shared references to values we