<commit_before>use super::compact::Compact;

/// A wrapper to make an `Option` of a nontrivial `Compact` possible.
/// Unfortunately, we can't blanket-`impl` that, since that overlaps
/// (for the compiler) with the `impl` for trivial `Copy` types...
#[derive(Clone)]
pub struct CompactOption<T: Compact + Clone>(pub Option<T>);

impl<T: Compact + Clone> ::std::ops::Deref for CompactOption<T> {
    type Target = Option<T>;

    fn deref(&self) -> &Option<T> {
        &self.0
    }
}

impl<T: Compact + Clone> ::std::ops::DerefMut for CompactOption<T> {
    fn deref_mut(&mut self) -> &mut Option<T> {
        &mut self.0
    }
}

impl<T: Clone + Compact> Compact for CompactOption<T> {
    fn is_still_compact(&self) -> bool {
        self.0.as_ref().map(|t| t.is_still_compact()).unwrap_or(
            true,
        )
    }

    fn dynamic_size_bytes(&self) -> usize {
        self.0.as_ref().map(|t| t.dynamic_size_bytes()).unwrap_or(0)
    }

    unsafe fn compact(source: *mut Self, dest: *mut Self, new_dynamic_part: *mut u8) {
        if let CompactOption(Some(ref mut s)) = *source {
            ::std::ptr::write(dest, CompactOption(Some(::std::mem::uninitialized())));
            if let CompactOption(Some(ref mut d)) = *dest {
                Compact::compact(s, d, new_dynamic_part);
            } else {
                unreachable!()
            }
        } else {
            ::std::ptr::write(dest, CompactOption(None));
        }
    }

    unsafe fn decompact(source: *const Self) -> Self {
        if let CompactOption(Some(ref s)) = *source {<commit_msg>Fix reachable unreachable code bug in CompactOption<commit_after>use super::compact::Compact;

/// A wrapper to make an `Option` of a nontrivial `Compact` possible.
/// Unfortunately, we can't blanket-`impl` that, since that overlaps
/// (for the compiler) with the `impl` for trivial `Copy` types...
#[derive(Clone)]
pub struct CompactOption<T: Compact + Clone>(pub Option<T>);

impl<T: Compact + Clone> ::std::ops::Deref for CompactOption<T> {
    type Target = Option<T>;

    fn deref(&self) -> &Option<T> {
        &self.0
    }
}

impl<T: Compact + Clone> ::std::ops::DerefMut for CompactOption<T> {
    fn deref_mut(&mut self) -> &mut Option<T> {
        &mut self.0
    }
}

impl<T: Clone + Compact> Compact for CompactOption<T> {
    fn is_still_compact(&self) -> bool {
        self.0.as_ref().map(|t| t.is_still_compact()).unwrap_or(
            true,
        )
    }

    fn dynamic_size_bytes(&self) -> usize {
        self.0.as_ref().map(|t| t.dynamic_size_bytes()).unwrap_or(0)
    }

    unsafe fn compact(source: *mut Self, dest: *mut Self, new_dynamic_part: *mut u8) {
        if let CompactOption(Some(ref mut s)) = *source {
            ::std::ptr::copy_nonoverlapping(source, dest, 1);
            if let CompactOption(Some(ref mut d)) = *dest {
                Compact::compact(s, d, new_dynamic_part);
            } else {
                unreachable!()
            }
        } else {
            ::std::ptr::write(dest, CompactOption(None));
        }
    }

    unsafe fn decompact(source: *const Self) -> Self {
        if let CompactOption(Some(ref s)) = *source {
{'fraction_non_alphanumeric': 0.15367623856106027, 'fraction_numerical': 0.0041022404544020195, 'mean_word_length': 2.6605080831408774, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4423261', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1062, 'n_words': 257}