Coverage Report

Created: 2025-11-16 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/alloc-stdlib-0.2.2/src/heap_alloc.rs
Line
Count
Source
1
use std;
2
3
4
use super::{SliceWrapper, SliceWrapperMut, Allocator};
5
6
use std::ops;
7
use std::ops::Range;
8
use std::boxed::Box;
9
use std::vec::Vec;
10
pub struct WrapBox<T>(std::boxed::Box<[T]>);
11
12
impl<T> From<Vec<T>> for WrapBox<T> {
13
1.24M
    fn from(data: Vec<T>) -> Self {
14
1.24M
        WrapBox(data.into_boxed_slice())
15
1.24M
    }
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::convert::From<alloc::vec::Vec<brotli_decompressor::huffman::HuffmanCode>>>::from
Line
Count
Source
13
314k
    fn from(data: Vec<T>) -> Self {
14
314k
        WrapBox(data.into_boxed_slice())
15
314k
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as core::convert::From<alloc::vec::Vec<u8>>>::from
Line
Count
Source
13
261k
    fn from(data: Vec<T>) -> Self {
14
261k
        WrapBox(data.into_boxed_slice())
15
261k
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::convert::From<alloc::vec::Vec<u32>>>::from
Line
Count
Source
13
127k
    fn from(data: Vec<T>) -> Self {
14
127k
        WrapBox(data.into_boxed_slice())
15
127k
    }
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::convert::From<alloc::vec::Vec<brotli_decompressor::huffman::HuffmanCode>>>::from
Line
Count
Source
13
123k
    fn from(data: Vec<T>) -> Self {
14
123k
        WrapBox(data.into_boxed_slice())
15
123k
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as core::convert::From<alloc::vec::Vec<u8>>>::from
Line
Count
Source
13
100k
    fn from(data: Vec<T>) -> Self {
14
100k
        WrapBox(data.into_boxed_slice())
15
100k
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::convert::From<alloc::vec::Vec<u32>>>::from
Line
Count
Source
13
38.3k
    fn from(data: Vec<T>) -> Self {
14
38.3k
        WrapBox(data.into_boxed_slice())
15
38.3k
    }
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::convert::From<alloc::vec::Vec<brotli_decompressor::huffman::HuffmanCode>>>::from
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as core::convert::From<alloc::vec::Vec<u8>>>::from
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as core::convert::From<alloc::vec::Vec<u32>>>::from
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::convert::From<alloc::vec::Vec<brotli_decompressor::huffman::HuffmanCode>>>::from
Line
Count
Source
13
122k
    fn from(data: Vec<T>) -> Self {
14
122k
        WrapBox(data.into_boxed_slice())
15
122k
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as core::convert::From<alloc::vec::Vec<u8>>>::from
Line
Count
Source
13
101k
    fn from(data: Vec<T>) -> Self {
14
101k
        WrapBox(data.into_boxed_slice())
15
101k
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::convert::From<alloc::vec::Vec<u32>>>::from
Line
Count
Source
13
50.3k
    fn from(data: Vec<T>) -> Self {
14
50.3k
        WrapBox(data.into_boxed_slice())
15
50.3k
    }
16
}
17
18
impl<T> Into<Box<[T]>> for WrapBox<T> {
19
    fn into(self) -> Box<[T]> {
20
        self.0
21
    }
22
}
23
24
impl<T> Default for WrapBox<T> {
25
17.6M
    fn default() -> Self {
26
17.6M
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
17.6M
       let b = v.into_boxed_slice();
28
17.6M
       return WrapBox::<T>(b);
29
17.6M
    }
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::default::Default>::default
Line
Count
Source
25
5.82M
    fn default() -> Self {
26
5.82M
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
5.82M
       let b = v.into_boxed_slice();
28
5.82M
       return WrapBox::<T>(b);
29
5.82M
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::default::Default>::default
Line
Count
Source
25
5.05M
    fn default() -> Self {
26
5.05M
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
5.05M
       let b = v.into_boxed_slice();
28
5.05M
       return WrapBox::<T>(b);
29
5.05M
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as core::default::Default>::default
Line
Count
Source
25
1.39M
    fn default() -> Self {
26
1.39M
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
1.39M
       let b = v.into_boxed_slice();
28
1.39M
       return WrapBox::<T>(b);
29
1.39M
    }
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::default::Default>::default
Line
Count
Source
25
1.00M
    fn default() -> Self {
26
1.00M
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
1.00M
       let b = v.into_boxed_slice();
28
1.00M
       return WrapBox::<T>(b);
29
1.00M
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as core::default::Default>::default
Line
Count
Source
25
490k
    fn default() -> Self {
26
490k
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
490k
       let b = v.into_boxed_slice();
28
490k
       return WrapBox::<T>(b);
29
490k
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::default::Default>::default
Line
Count
Source
25
762k
    fn default() -> Self {
26
762k
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
762k
       let b = v.into_boxed_slice();
28
762k
       return WrapBox::<T>(b);
29
762k
    }
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::default::Default>::default
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as core::default::Default>::default
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as core::default::Default>::default
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::default::Default>::default
Line
Count
Source
25
1.44M
    fn default() -> Self {
26
1.44M
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
1.44M
       let b = v.into_boxed_slice();
28
1.44M
       return WrapBox::<T>(b);
29
1.44M
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::default::Default>::default
Line
Count
Source
25
1.17M
    fn default() -> Self {
26
1.17M
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
1.17M
       let b = v.into_boxed_slice();
28
1.17M
       return WrapBox::<T>(b);
29
1.17M
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as core::default::Default>::default
Line
Count
Source
25
479k
    fn default() -> Self {
26
479k
       let v : std::vec::Vec<T> = std::vec::Vec::new();
27
479k
       let b = v.into_boxed_slice();
28
479k
       return WrapBox::<T>(b);
29
479k
    }
30
}
31
32
impl<T> super::SliceWrapper<T> for WrapBox<T> {
33
6.70G
    fn slice(&self) -> & [T] {
34
6.70G
       return &*self.0
35
6.70G
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapper<u32>>::slice
Line
Count
Source
33
1.96M
    fn slice(&self) -> & [T] {
34
1.96M
       return &*self.0
35
1.96M
    }
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapper<brotli_decompressor::huffman::HuffmanCode>>::slice
Line
Count
Source
33
7.08M
    fn slice(&self) -> & [T] {
34
7.08M
       return &*self.0
35
7.08M
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapper<u8>>::slice
Line
Count
Source
33
5.30G
    fn slice(&self) -> & [T] {
34
5.30G
       return &*self.0
35
5.30G
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapper<u32>>::slice
Line
Count
Source
33
175k
    fn slice(&self) -> & [T] {
34
175k
       return &*self.0
35
175k
    }
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapper<brotli_decompressor::huffman::HuffmanCode>>::slice
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapper<u8>>::slice
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapper<u32>>::slice
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapper<brotli_decompressor::huffman::HuffmanCode>>::slice
Line
Count
Source
33
20.1M
    fn slice(&self) -> & [T] {
34
20.1M
       return &*self.0
35
20.1M
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapper<u8>>::slice
Line
Count
Source
33
493M
    fn slice(&self) -> & [T] {
34
493M
       return &*self.0
35
493M
    }
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapper<brotli_decompressor::huffman::HuffmanCode>>::slice
Line
Count
Source
33
1.61M
    fn slice(&self) -> & [T] {
34
1.61M
       return &*self.0
35
1.61M
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapper<u8>>::slice
Line
Count
Source
33
867M
    fn slice(&self) -> & [T] {
34
867M
       return &*self.0
35
867M
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapper<u32>>::slice
Line
Count
Source
33
377k
    fn slice(&self) -> & [T] {
34
377k
       return &*self.0
35
377k
    }
36
}
37
38
impl<T> super::SliceWrapperMut<T> for WrapBox<T> {
39
9.00G
    fn slice_mut(&mut self) -> &mut [T] {
40
9.00G
       return &mut*self.0
41
9.00G
    }
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<brotli_decompressor::huffman::HuffmanCode>>::slice_mut
Line
Count
Source
39
459k
    fn slice_mut(&mut self) -> &mut [T] {
40
459k
       return &mut*self.0
41
459k
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u8>>::slice_mut
Line
Count
Source
39
6.65G
    fn slice_mut(&mut self) -> &mut [T] {
40
6.65G
       return &mut*self.0
41
6.65G
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u32>>::slice_mut
Line
Count
Source
39
160k
    fn slice_mut(&mut self) -> &mut [T] {
40
160k
       return &mut*self.0
41
160k
    }
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<brotli_decompressor::huffman::HuffmanCode>>::slice_mut
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u8>>::slice_mut
Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u32>>::slice_mut
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<brotli_decompressor::huffman::HuffmanCode>>::slice_mut
Line
Count
Source
39
110k
    fn slice_mut(&mut self) -> &mut [T] {
40
110k
       return &mut*self.0
41
110k
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u8>>::slice_mut
Line
Count
Source
39
741M
    fn slice_mut(&mut self) -> &mut [T] {
40
741M
       return &mut*self.0
41
741M
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u32>>::slice_mut
Line
Count
Source
39
46.3k
    fn slice_mut(&mut self) -> &mut [T] {
40
46.3k
       return &mut*self.0
41
46.3k
    }
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<brotli_decompressor::huffman::HuffmanCode>>::slice_mut
Line
Count
Source
39
169k
    fn slice_mut(&mut self) -> &mut [T] {
40
169k
       return &mut*self.0
41
169k
    }
<alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u32>>::slice_mut
Line
Count
Source
39
51.5k
    fn slice_mut(&mut self) -> &mut [T] {
40
51.5k
       return &mut*self.0
41
51.5k
    }
<alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u8>>::slice_mut
Line
Count
Source
39
1.60G
    fn slice_mut(&mut self) -> &mut [T] {
40
1.60G
       return &mut*self.0
41
1.60G
    }
42
}
43
impl<T> ops::Index<usize> for WrapBox<T> {
44
  type Output = T;
45
  fn index(&self, index: usize) -> &T {
46
    &(*self.0)[index]
47
  }
48
}
49
50
impl<T> ops::IndexMut<usize> for WrapBox<T> {
51
  fn index_mut(&mut self, index: usize) -> &mut T {
52
    &mut (*self.0)[index]
53
  }
54
}
55
56
impl<T> ops::Index<Range<usize>> for WrapBox<T> {
57
  type Output = [T];
58
  fn index(&self, index: Range<usize>) -> &[T] {
59
    &(*self.0)[index]
60
  }
61
}
62
63
impl<T> ops::IndexMut<Range<usize>> for WrapBox<T> {
64
  fn index_mut(&mut self, index: Range<usize>) -> &mut [T] {
65
    &mut (*self.0)[index]
66
  }
67
}
68
69
70
pub struct HeapAlloc<T : Clone>{
71
   pub default_value : T,
72
}
73
74
impl<T: Clone+Default> Default for HeapAlloc<T> {
75
    fn default() -> Self {
76
        Self::new(T::default())
77
    }
78
}
79
80
impl<T : Clone> HeapAlloc<T> {
81
   pub fn new(data : T) -> HeapAlloc<T> {
82
      return HeapAlloc::<T>{default_value : data};
83
   }
84
}
85
86
impl<T : Clone> super::Allocator<T> for HeapAlloc<T> {
87
   type AllocatedMemory = WrapBox<T>;
88
   fn alloc_cell(self : &mut HeapAlloc<T>, len : usize) -> WrapBox<T> {
89
90
       let v : std::vec::Vec<T> = vec![self.default_value.clone();len];
91
       let b = v.into_boxed_slice();
92
       return WrapBox::<T>(b);
93
   }
94
   fn free_cell(self : &mut HeapAlloc<T>, _data : WrapBox<T>) {
95
96
   }
97
}
98
99
#[deprecated]
100
pub type HeapAllocUninitialized<T> = HeapAlloc<T>;
101
102
103
pub struct HeapPrealloc<'a, T : 'a> {
104
   freelist : std::boxed::Box<[&'a mut [T]]>,
105
}
106
define_stack_allocator_traits!(HeapPrealloc, heap);
107
108
impl<'a, T : Clone+'a> HeapPrealloc<'a, T> {
109
    fn make_freelist(freelist_size : usize) -> std::boxed::Box<[&'a mut[T]]> {
110
        let mut retval = Vec::<&'a mut[T]>::with_capacity(freelist_size);
111
        for _i in 0..freelist_size {
112
            retval.push(&mut[]);
113
        }
114
        return retval.into_boxed_slice();
115
    }
116
    pub fn new_allocator(freelist_size : usize,
117
                     memory_pool : &'a mut Box<[T]>,
118
                     initializer : fn(&mut[T])) -> super::StackAllocator<'a, T, HeapPrealloc<'a, T> > {
119
        let mut retval = super::StackAllocator::<T, HeapPrealloc<T> > {
120
            nop : &mut [],
121
            system_resources : HeapPrealloc::<T> {
122
                freelist : Self::make_freelist(freelist_size),
123
            },
124
            free_list_start : freelist_size,
125
            free_list_overflow_count : 0,
126
            initialize : initializer,
127
        };
128
        retval.free_cell(super::AllocatedStackMemory::<T>{mem:&mut*memory_pool});
129
        return retval;
130
    }
131
    #[cfg(feature="unsafe")]
132
    pub unsafe fn new_uninitialized_memory_pool(len : usize) -> Box<[T]> {
133
        let mut v : std::vec::Vec<T> = std::vec::Vec::with_capacity(len);
134
        v.set_len(len);
135
        return v.into_boxed_slice();
136
    }
137
}
138