/// Register a new type, merging newly related `TypeGroup`s.
Register a new type, merging newly related `TypeGroup`s.
Register a new type merging newly related ` TypeGroup ` s .
pub(crate) fn register(&mut self, type_state: &'static TypeState) {
        debug_assert!(!self.groups.contains_key(&type_state.type_info));
        let relations = unsafe { &*type_state.relations.get() }.active_relations();
        let groups: HashSet<*const TypeGroup> = relations
            .iter()
            .filter_map(|ti| self.groups.get(ti).cloned())
            .collect();
        let group = Box::leak(Box::new(TypeGroup::default()));
        group.related.push(type_state);
        let gc_in_progress = groups.iter().cloned().fold(false, |gc_in_progress, tg| {
            let tg = unsafe { &mut *(tg as *mut TypeGroup) };
            group.free.merge(&mut tg.free);
            group.related.extend(tg.related.iter());
            // Registering a new type resets gc state.
            // If a collection was in progress it is restarted.
            let r = gc_in_progress || tg.gc_in_progress.is_some();
            // Free the old group
            unsafe { drop(Box::from_raw(tg as *const _ as *mut TypeGroup)) }
            r
        });
        // Add new type_state and update old type_state => TypeGroup mappings.
        group.related.iter().for_each(|ts| {
            self.groups.insert(&ts.type_info, group);
        });
        if gc_in_progress {
            group.major_gc();
        };
    }
pub ( crate ) fn register ( & mut self , type_state : & ' static TypeState ) { debug_assert ! ( self groups contains_key ( type_state type_info ) ) ; let relations = unsafe { & * type_state . relations . get ( ) } . active_relations ( ) ; let groups : HashSet < * const TypeGroup > = relations . iter ( ) . filter_map ( | ti | self . groups . get ( ti ) . cloned ( ) ) . collect ( ) ; let group = Box :: leak ( Box :: new ( TypeGroup :: default ( ) ) ) ; group . related . push ( type_state ) ; let gc_in_progress = groups . iter ( ) . cloned ( ) . fold ( false , | gc_in_progress , tg | { let tg = unsafe { & mut * ( tg as * mut TypeGroup ) } ; group . free . merge ( & mut tg . free ) ; group . related . extend ( tg . related . iter ( ) ) ; // Registering a new type resets gc state. // If a collection was in progress it is restarted. let r = gc_in_progress || tg . gc_in_progress . is_some ( ) ; // Free the old group unsafe { drop ( Box :: from_raw ( tg as * const _ as * mut TypeGroup ) ) } r } ) ; // Add new type_state and update old type_state => TypeGroup mappings. group . related . iter ( ) . for_each ( | ts | { self . groups . insert ( & ts . type_info , group ) ; } ) ; if gc_in_progress { group . major_gc ( ) ; } ; }
Register a new type, merging newly related `TypeGroup`s.
Register a new type merging newly related ` TypeGroup ` s .
&mut self
type_state
&'static TypeState