polars_core/chunked_array/
drop.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::chunked_array::object::extension::drop::drop_list;
use crate::prelude::*;

#[inline(never)]
#[cold]
fn drop_slow<T: PolarsDataType>(ca: &mut ChunkedArray<T>) {
    // SAFETY:
    // guarded by the type system
    // the transmute only convinces the type system that we are a list
    #[allow(clippy::transmute_undefined_repr)]
    unsafe {
        drop_list(std::mem::transmute::<&mut ChunkedArray<T>, &ListChunked>(
            ca,
        ))
    }
}

impl<T: PolarsDataType> Drop for ChunkedArray<T> {
    fn drop(&mut self) {
        if matches!(self.dtype(), DataType::List(_)) {
            drop_slow(self);
        }
    }
}